From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: New optimized normal-type mutex?
Date: Thu, 30 Jul 2015 01:49:20 +0200 [thread overview]
Message-ID: <1438213760.10742.5.camel@inria.fr> (raw)
In-Reply-To: <20150729233054.GZ16376@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 2189 bytes --]
Am Mittwoch, den 29.07.2015, 19:30 -0400 schrieb Rich Felker:
> On Thu, Jul 30, 2015 at 12:11:15AM +0200, Jens Gustedt wrote:
> > Hello,
> >
> > Am Mittwoch, den 29.07.2015, 14:09 +0200 schrieb Joakim Sindholt:
> > > So he went on and suggested that a cas-less lock was possible with
> > > a_fetch_add however I can't make it work and I don't think he can
> > > either. His idea however is sound: the one who flips the sign bit takes
> > > the lock. Based on that I've cobbled together a different lock that will
> > > probably perform worse than this approach but none-the-less be correct
> > > as far as I can tell.
> > >
> > > The difference is that we consider the lock owner a waiter as well, thus
> > > requiring a cas loop in the unlock function to remove itself, so to
> > > speak, from the waiter count. a_fetch_and also turns into a cas loop so
> > > I consider this fairly minor.
> > > This makes the wait loop a little simpler while still maintaining a
> > > waiter count and still only using one int.
> >
> > Nice ideas!
> >
> > After the recent discussion about the problems on x86_64 I was trying
> > to come up with a simple lock for the atomics, and I came thinking
> > along the same lines.
>
> Unfortunately, discussion on IRC has revealed a potentially
> show-stopping issue for merging the waiter count into the futex word:
> arrival of new waiters causes EAGAIN from futex_wait. I don't know any
> good way around this, but it's probably the reason designs like this
> have not been popular before.
Hm, could you be more specific about where this hurts?
In the code I have there is
for (;val & lockbit;) {
__syscall(SYS_futex, loc, FUTEX_WAIT, val, 0);
val = atomic_load_explicit(loc, memory_order_consume);
}
so this should be robust against spurious wakeups, no?
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: 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: 181 bytes --]
next prev parent reply other threads:[~2015-07-29 23:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-21 23:44 Rich Felker
2015-05-22 7:30 ` Jens Gustedt
2015-05-22 7:51 ` Rich Felker
2015-07-29 12:09 ` Joakim Sindholt
2015-07-29 22:11 ` Jens Gustedt
2015-07-29 23:30 ` Rich Felker
2015-07-29 23:49 ` Jens Gustedt [this message]
2015-07-30 0:10 ` Rich Felker
2015-07-30 8:07 ` Jens Gustedt
2015-07-30 9:10 ` Jens Gustedt
2015-07-30 9:36 ` Alexander Monakov
2015-07-30 10:00 ` Jens Gustedt
2015-07-30 11:37 ` Alexander Monakov
2015-07-30 13:46 ` Rich Felker
2015-07-30 16:07 ` Jens Gustedt
2015-08-03 16:36 ` Alexander Monakov
2015-08-03 19:43 ` Jens Gustedt
2015-08-03 20:05 ` Isaac Dunham
2015-08-04 5:49 ` Jens Gustedt
2015-07-30 13:45 ` 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=1438213760.10742.5.camel@inria.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).