> > See half way down
> > http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml
[quoted text clipped - 4 lines]
> queue.Count to be 0 when Monitor.Wait exits, considering the implementation
> of that class?
Yes - consider the case where there are two threads consuming work
items, and one producing.
Consumer 1 Consumer 2 Producer
Enter listLock
queue.Count==0 - yes
Wait for listLock
Enter listLock
Enter listLock (start)
Queue item
queue.Count==1 - yes
Pulse listLock
Exit listLock
Enter listLock (complete)
queue.Count==0 - no
Dequeue item
Exit listLock
Wake up
Reaquire listLock
queue.Count is still 0, so need to wait again

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Cool Guy - 24 May 2005 22:58 GMT
> Consumer 1 Consumer 2 Producer
>
[quoted text clipped - 19 lines]
> Reaquire listLock
> queue.Count is still 0, so need to wait again
Ah, of course! My confused arose by me thinking that the call to
Monitor.Pulse would make the call to Monitor.Wait return immediately --
before anything else aquires a lock.
Jon, when I look up 'helpful' in the dictionary, there is a picture of you.
;-) Thanks!