Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 06 Aug 2014 12:32:52 +0200
From: Jens Gustedt <>
Subject: Re: Explaining cond var destroy [Re: C threads, v3.0]

Am Mittwoch, den 06.08.2014, 06:03 -0400 schrieb Rich Felker:
> On Wed, Aug 06, 2014 at 11:41:04AM +0200, Jens Gustedt wrote:
> > I am not sure that this would easily be possible with the current
> > implementation, but I think that this would be ideal.
> Yes, that would be my ideal too, but I'm not sure it's possible. Well,
> not with an efficient implementation anyway. There's a trivial
> implementation where pthread_cond_timedwait is basically just:
> a_store(&c->_tid, self->tid);
> pthread_mutex_unlock(mtx);
> __timedwait(&c->tid, self->tid, ts, clock, ts, cleanup, mtx, 0);
> pthread_mutex_lock(mtx);
> This makes signal and broadcast operations utterly trivial (just set
> c->tid to 0 and call __wake with 1 or INT_MAX as the argument), but it
> has lots of spurious wakes under contention,


> I think, and perhaps
> other serious drawbacks too. If I remember correctly, musl's original
> implementation looked something like the above, but I was also having
> a hard time figuring out how to work requeue-to-mutex (which makes a
> big deal to performance on big broadcasts) into it.

Look into pthread_cond_broadcast. I think this could do better
bookkeeping. Currently it does its case analysis with a mildly
complicated expression in preparing the arguments to the
requeue-syscall. I think we could be better off by doing a case
analysis beforehand and update the different "waiters" variables
accordingly *before* the syscall. So the targeted threads wouldn't
have to do any bookkeeping when coming back from wait.

Maybe this even would help to reduce the condition state from two
"waiters" fields to a single one.


:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: ::

Download attachment "signature.asc" of type "application/pgp-signature" (199 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.