[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: mark benedetto king <mbk_at_lowlatency.com>
Date: 2003-09-10 14:29:39 CEST

On Wed, Sep 10, 2003 at 08:22:48AM -0400, mark benedetto king wrote:
>
> wait(cond,mutex):
> acquire(cond->mutex)
> cond->num_waiters++
> release(cond->mutex)
> release(mutex)
> down(cond->sem)
> up(cond->ack)
> acquire(cond->mutex)
> cond->num_waiters--
> release(cond->mutex)
> acquire(mutex)
>
> signal(cond):
> acquire(cond->mutex)
> up(cond->sem,min(1, cond->num_waiters))
> down(cond->ack,min(1, cond->num_waiters))
> release(cond->mutex)
>
> broadcast(cond):
> acquire(cond->mutex)
> up(cond->sem,cond->num_waiters)
> down(cond->ack,cond->num_waiters);
> release(cond->mutex)
>

I spoke too soon; this implementation has a problem with

Thread1 Thread2
wait()
                 signal()
                 signal()

There is an interleaving that causes the second signal() to hang, waiting
for a waiter that can never come, since Thread2 holds cond->mutex.
I give up for today. :-)

--ben

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Sep 10 14:30:26 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.