[gambit-list] Deadlock problem

Marc Feeley feeley at iro.umontreal.ca
Wed Aug 10 18:56:05 EDT 2005

On 9-Aug-05, at 2:55 PM, Matthew Morgan wrote:

> I can't figure out why this deadlocks on me (I'm using beta 14):
> (let ((x (open-vector)))
>   (thread-start! (make-thread (lambda () (write 1 x))))
>   (thread-start! (make-thread (lambda () (write 2 x))))
>   (read x)
>   (read x))
> *** ERROR IN ##thread-deadlock-action! -- Deadlock detected
> Shouldn't this run to completion (possibly blocking at times to wait
> for the writes), and return either 2 or 1?

I/O is buffered, so you need to force the output to be sent to the  
vector-port (and available to be read).  This is what you should do:

(let ((x (open-vector)))
   (thread-start! (make-thread (lambda () (write 1 x) (force-output  
   (thread-start! (make-thread (lambda () (write 2 x) (force-output  
   (read x)
   (read x))


More information about the Gambit-list mailing list