Well, I'm humbled :-)
How about the following (pseudo-Python again :-)):
wait(cond,mutex):
e = new event
lock(cond.mutex)
push(e.waiters, e)
unlock(cond.mutex)
SignalObjectAndWait(mutex, e)
lock(mutex)
signal(cond):
lock(cond.mutex)
e = shift(e.waiters)
unlock(cond.mutex)
SetEvent(e)
broadcast(cond):
lock(cond.mutex)
waiters = e.waiters
e.waiters = []
unlock(cond.mutex)
for e in waiters:
SetEvent(e)
It's simpler than the version in the article you linked (sorry, I forgot the
link), as well as not blocking the broadcaster until the last thread is
awakened. The list of waiters can be implemented as a linked list of stack-
based structures to avoid any dynamic memory requirements.
The "SignalObjectAndWait" can also be replaced by
unlock(mutex)
WaitEvent(e)
which will still work on older Win32, and will not have the "lost wakeup"
problem (since I use only manual-reset events).
So, am I right or am I right? ;-)
-az
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Sep 12 16:34:54 2003