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

Re: svn commit: rev 7004 - branches/svnserve-thread-pools/subversion/svnserve

From: mark benedetto king <mbk_at_lowlatency.com>
Date: 2003-09-10 00:11:30 CEST

On Tue, Sep 09, 2003 at 10:33:06PM +0200, Branko ??ibej wrote:
>
> mbk: After a quick glance at your patch, I can say that you're making
> the same mistakes I did in my patches. :-)
>

I'm not offended (proud to be in such good company, even), but I am
wondering what mistakes you saw.

Error handling aside (and some minor optimizations removed), things are
essentially:

wait(cond, mutex):
  # section 1:
  # wait for pending signals to be delivered
  while 1:
    acquire(cond->mutex)
    if !cond->num_undelivered:
      break
    release(cond->mutex)

  # section 2:
  # add self as waiter
  cond->num_waiters++
  release(mutex)
  release(cond->mutex)

  # section 3:
  # wait for a signal
  while 1:
    wait(cond->event)
    acquire(cond->mutex)
    if cond->num_undelivered:
      cond->num_undelivered--
      if !cond->num_undelivered:
        reset(cond->event)
      cond->num_waiters--;
      release(cond->mutex)
      acquire(mutex)
      return
    release(cond->mutex)

signal(cond):
  acquire(cond->mutex)
  cond->num_undelivered = min(cond->num_waiters, cond->num_undelivered + 1)
  set(cond->event)
  release(cond->mutex)

broadcast(cond):
  acquire(cond->mutex)
  cond->num_undelivered = cond->num_waiters
  set(cond->event)
  release(cond->mutex)

If a thread enters section 1 of wait(), it cannot proceed until all pending
signals have been delivered, and when it does, it holds cond->mutex, so
no more signals may be delivered until after it completes section 2.

Upon entering section 3, it is possible that an event has already been
signalled. If so, execution may proceed (or, obviously, be pre-empted).
If not, the thread sleeps. It does not hold cond->mutex, so signals
may occur.

Once a signal occurs, one or more threads will wake up and compete for the
signal. It is important to note that they may not all wake up immediately;
cond->event must not be reset until all signals have been delivered.
Each one of these threads will attempt to acquire cond->mutex. Once a
thread holds the mutex, it may examine cond->num_undelivered to determine
if there are, in fact, undelivered signals. If so, it may decrement
the count (and reset the event if the count has gone to zero), and remove
itself from the wait count.

--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 00:12:27 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.