mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [PATCH 2/2] avoid taking _c_lock if we know it isn't necessary
Date: Wed, 27 Aug 2014 23:30:26 +0200	[thread overview]
Message-ID: <1409175026.4476.71.camel@eris.loria.fr> (raw)
In-Reply-To: <20140827200756.GS12888@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 3547 bytes --]

Am Mittwoch, den 27.08.2014, 16:07 -0400 schrieb Rich Felker:
> On Wed, Aug 27, 2014 at 11:57:47AM +0200, Jens Gustedt wrote:
> > +		/* Since this leaving waiter might not have held the _c_lock, the following       */
> > +		/* __wake might be issued when the signaler is still inside its CS.               */
> > +		/* But if so, this avoids a __wait of the signaler, which more important.         */
> > +		/* This should not target any spurious wake up in any other thread:               */
> > +		/* ref is on the stack of the signaler, and that signaler is still alive.         */
> >  		if (ref) {
> >  			if (a_fetch_add(ref, -1)==1)
> >  				__wake(ref, 1, 1);
> 
> Can't you avoid that with the design I suggested, having the signaler
> use an extra ref count on itself, which it decrements right before
> waiting?

Probably, but I have not completely thought this through. But if so
this would round up this series nicely with a third patch.

> Aside from that, based on my reading so far, these patches look like
> they should work correctly. But since we both want to get C11 threads
> done,

Exactly, that was my idea, freeze the main ideas in some short patches
and have them in the list archives for future use.

> let's put them aside for now (pending some testing for
> measurable benefits).


> I also have some other potential changes to this
> code based on my latest comments to:
> 
> http://austingroupbugs.net/view.php?id=609
> 
> regarding things they seem to deem as requirements, and which musl
> does not satisfy, that are specified in non-normative text. So there's
> likely to be more cond var work to do before the release still...

Ah, the cancelation stuff. As if condition variables wouldn't be
complicated enough already, without cancelation. We already have two
different ordered sequences of events, those on the cv and those on
the mutex. The discussion (and our implementation struggles) already
shows how difficult it is to get these two linear sequences ordered in
a convenient way. If you add a third set of events that are neither
ordered among themselves (cancelation to different threads are
asynchronous) nor with any of the two sequences, the semantics aren't
clear at all. (This is why I think that generally thread cancelation
is not a good idea, and why it is not very widely used. It contributes
for more than 50% to the complexity of the implementation of
pthreads.)

But with the current implementation, I would think that it basically
fulfills (or can be easily made to fulfill) the requirement that
cancelation would not be "consuming" a signal when some other thread
is available. We are marking threads as WAITING, LEAVING or SIGNALED
and only for WAITING, a thread can be consired "blocked" on the
cv. The transition between these is atomic, and so once a signaler
marked a thread SIGNALED, it is not blocked and has rightly consumed
the signal.

I didn't check, though, if timedwait returns 0 in that case the final
value is SIGNALED. If not, that would probably be a reasonable way to
go. Something like

if (SIGNALED && "mutex sucessfully acquired") return 0
else return the proper error code as before

Jens



-- 
:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2014-08-27 21:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27  9:57 Jens Gustedt
2014-08-27 20:07 ` Rich Felker
2014-08-27 21:30   ` Jens Gustedt [this message]
2014-08-27 21:48     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409175026.4476.71.camel@eris.loria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).