Re: [Sablevm-developer] Partial success w/ debbuggtk - screenshot!
Brought to you by:
egagnon
From: Archie C. <ar...@de...> - 2004-01-20 16:00:09
|
David B=E9langer wrote: > This requires implementing the Thread interrupt()ing mechanism in > SableVM. If I remember well there is no functionality right now. > In addition to Thread.interrupted(), .interrupt(), etc. > Object.wait(), Process.waitFor(), maybe also join() and sleep()... > need to be modified to throw InterruptedException. I am interested in hearing people's ideas about how to best implement Thread.interrupt(). First observation: if you implement join(), sleep(), and waitFor() using wait(), then you get them for free. So look at the wait() case. There will have to be some interruption state associated with each that is updated with compare&swap. One possibility: INTERRUPT_CLEAR /* not interrupted, not interruptible */ INTERRUPT_SET /* interrupted, but not asleep yet */ INTERRUPT_INTERRUPTIBLE /* sleeping in wait() and interruptible *= / INTERRUPT_INTERRUPTED /* waking up to handle interruption */ Not sure if the last state is needed. To wake up a thread in wait(), the interrupting thread will have to notify the wait() condition variable. However, there may be multiple threads waiting. To ensure the correct one is woken up & notices its interruption state has changed, we must use pthread_cond_broadcast() instead of pthread_cond_signal(). So some threads will wake up spuriously. This implies the wait() algorithm will have to loop (i.e., handle the case where the wakeup was spurious). But we should be doing this anyway according to: http://www.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_wait.html "Spurious wakeups from the pthread_cond_wait() or pthread_cond_timedwait(= ) functions may occur." Interested to hear others' thoughts. I haven't really looked at how other VMs do it, there's probably a better way than above. -Archie _________________________________________________________________________= _ Archie Cobbs * Halloo Communications * http://www.halloo.co= m |