[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [OT] Win32 condition variable implementation

From: Branko Čibej <brane_at_xbc.nu>
Date: 2003-09-11 09:16:58 CEST

Alon Ziv wrote:

>Just a note from a lurker--
>I'm maintaining a home-grown OS, and we also have a "condition variable"
>construct. The implementation is along the lines of:
>
>wait(cond):
> e = new event
> lock(cond->mutex)
> cond->waiters = [cond->waiters, e]
> unlock(cond->mutex)
> wait(e)
>
>signal(cond):
> lock(cond->mutex)
> e = pop(cond->waiters)
> unlock(cond->mutex)
> signal(e)
>
>broadcast(cond):
> lock(cond->mutex)
> waiters = cond->waiters
> cond->waiters = []
> unlock(cond->mutex)
> for e in waiters:
> signal(e)
>
>(Sorry if I'm using too many Perl-isms in the Python-pseudocode...)
>
>The above is (as far as I know) free from any races, deadlocks, etc.
>
>
Yes, but it doesn't implement the semantics of POSIX condition variables
-- it doesn't release and reacquire the mutex associated with the
condition whie waiting for the signal. The problem with these simple
inplementations on Windows has always been that

    release(mutex)
    wait(event)
    acquire(mutex)

has a race condition because the release and wait can't be performed
atomically.

-- 
Brane Čibej   <brane_at_xbc.nu>   http://www.xbc.nu/brane/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Sep 11 09:17:39 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.