Semaphore class in Open3270

Topics: Developer Forum, Project Management Forum, User Forum
Mar 5, 2008 at 5:53 PM
Edited Mar 5, 2008 at 6:45 PM
I have posted, on CodeProject to staceyw, for a discussion on the usage of Monitor.Wait in the Semaphore.Aquire(timeout) method.

I believe that there is a missunderstanding on how Monitor.Wait works. But, I could very well be wrong, so I am posting here to try to deterimne if my understanding of how it is being used in the Semaphore.Aquire method is correct.

In the .Net documentation, it says that Monitor.Wait(object, timeout) returns only after the lock on the object is re-aquired and that the return value indicates if the lock was re-aquired before or after the timeout given. What the return value indicates is whether or not the wait queue was signaled (Pulsed) and caused the thread to be put on the ready queue before the timeout elapsed or whether it was put on the ready queue after that timeout period. The thead still did aquire the lock in either case before returning.

If the Semaphore.Aquire(timeout) method intends to timeout if the lock is not re-aquired before timeout period, then the usage of Monitor.Wait will not do the trick, instead, the code would need to use Monitor.TryEnter(timeout) and that would require more code to ensure that interrupts and Monitor.Exit are handled properly.

Does anyone have any input on this? Am I seeing things clearly?