[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: Philip Martin <philip_at_codematters.co.uk>
Date: 2003-09-10 16:07:21 CEST

mark benedetto king <mbk@lowlatency.com> writes:

> On Wed, Sep 10, 2003 at 08:29:39AM -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(mutex)
>
> deliver(cond,count):
> up(cond->sem, count)
> down(cond->ack, count)
> count->num_waiters -= count
>
> signal(cond):
> acquire(cond->mutex)
> deliver(cond, min(1, cond->num_waiters))
> release(cond->mutex)
>
> broadcast(cond):
> acquire(cond->mutex)
> deliver(cond, cond->num_waiters);
> release(cond->mutex)

I am not familiar with the sematics of the Win32 "counting
semaphores", your up/down in the algorithm above, but that algorithm
doesn't look right. What behaviour you are trying to achieve, are you
after the POSIX behaviour where broadcast wakes every waiting thread?
What about this scenario

  thread 1 waits
  thread 2 waits
  thread 3 broadcasts
  thread 1 wakes up and runs
  thread 1 waits again
  thread 1 wakes up and runs
  thread 1 waits again

The broadcast didn't wake thread 2. That could be enough to cause
deadlock if the application relied on POSIX behaviour.

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Sep 10 16:08:09 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.