From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [PATCH] a new lock algorithm with lock value and CS counts in the same atomic int
Date: Sun, 18 Jun 2017 13:10:56 +0200 [thread overview]
Message-ID: <20170618131056.5df46232@inria.fr> (raw)
In-Reply-To: <alpine.LNX.2.20.13.1706181257440.21867@monopod.intra.ispras.ru>
[-- Attachment #1: Type: text/plain, Size: 1368 bytes --]
Hello Alexander,
On Sun, 18 Jun 2017 13:01:18 +0300 (MSK) Alexander Monakov
<amonakov@ispras.ru> wrote:
> On Fri, 16 Jun 2017, Jens Gustedt wrote:
> > void __lock(volatile int *l)
> > {
> > - if (libc.threads_minus_1)
> > - while (a_swap(l, 1)) __wait(l, l+1, 1, 1);
> > + /* This test is mostly useless, now. Leaving it to the
> > first CAS is
> > + probably just as efficient. */
> > + if (libc.threads_minus_1) {
> [...]
> > void __unlock(volatile int *l)
> > {
> > - if (l[0]) {
> > - a_store(l, 0);
> > - if (l[1]) __wake(l, 1, 1);
> > + if (a_fetch_add(l, INT_MAX) != -INT_MAX) {
> > + __syscall(SYS_futex, l, FUTEX_WAKE|FUTEX_PRIVATE,
> > 1); }
> > }
>
> This looks wrong in single-threaded case, __lock doesn't touch the
> lock, but __unlock modifies it unconditionally.
Right, probably there should be the same test as for the lock case. Or
we should drop that test all along. I don't think that it still serves
much purpose here. This is just trading one memory access against
another.
Thanks
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: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2017-06-18 11:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-16 7:11 Jens Gustedt
2017-06-18 10:01 ` Alexander Monakov
2017-06-18 11:10 ` Jens Gustedt [this message]
2017-06-18 11:49 ` Alexander Monakov
2017-06-18 14:45 ` Rich Felker
2017-06-18 14:58 ` Alexander Monakov
2017-06-18 13:40 ` Alexander Monakov
2017-06-18 14:53 ` Rich Felker
2017-06-18 15:05 ` Alexander Monakov
2017-06-18 16:04 ` Rich Felker
2017-06-18 17:31 ` Jens Gustedt
2017-06-18 19:32 ` Jens Gustedt
2017-06-18 20:20 ` Rich Felker
2017-06-18 20:38 ` Alexander Monakov
2017-06-18 17:40 ` Jens Gustedt
2017-06-18 15:01 ` 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=20170618131056.5df46232@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).