mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <>
To: Markus Wichmann <>
Subject: Re: [musl] Suggestion for thread safety
Date: Wed, 23 Feb 2022 15:06:35 -0500	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <20220223185746.GB2079@voyager>

On Wed, Feb 23, 2022 at 07:57:46PM +0100, Markus Wichmann wrote:
> On Wed, Feb 23, 2022 at 12:30:43AM +0000, Lee Shallis wrote:
> > in other words just
> > with LOCK & pauseCB I've achieved thread safety without the file
> > knowing anything about the system api,
> You have indeed not done that. You have instead written the word "lock"
> enough times to give someone skim-reading the file false confidence that
> this stuff will actually work in a multi-threaded context, only to then
> fail under high load for inexplicable reasons.
> I keep seeing this behavior from programmers that ought to know better.
> You see, an exclusive lock consists of two parts: The mutual exclusion
> and the sleep. And yes, spinlocks skip the second part, but my point is:
> The mutual exclusion is actually the easy part, and any hack with a
> Messiah complex and a CPU manual can do it. The sleep is the hard part,
> if you want to do it right. It needs to be Goldilocks. Too short, and
> you are wasting resources (every time your thread spins in the loop is
> time the CPU could have better spent on other threads), too long and you
> are wasting time.
> Your sleep is definitely too short, and you didn't even get the mutual
> exclusion part right.

It's worse: it has *three* parts, the third being the _synchronizing
memory_ part, which I'm guessing this made no attempt to do at all.
That's where all the time in a lock is actually spent, and if you
somehow avoid doing that (note: x86 will mostly do it for you and send
you the bill), things will blow up spectacularly.

  reply	other threads:[~2022-02-23 20:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 11:36 Lee Shallis
2022-02-21 17:42 ` Markus Wichmann
2022-02-23  0:30   ` Lee Shallis
2022-02-23 18:57     ` Markus Wichmann
2022-02-23 20:06       ` Rich Felker [this message]
2022-02-26  9:56       ` Lee Shallis
2022-02-26 11:38         ` Joakim Sindholt
2022-02-27 23:32           ` Lee Shallis
2022-02-28  0:15             ` Rich Felker
2022-02-28  8:48             ` Joakim Sindholt
2022-02-28 14:43               ` Lee Shallis
2022-02-28 15:19                 ` Rich Felker
2022-02-28 15:50                 ` Joakim Sindholt
2022-02-28 16:07                   ` Lee Shallis
2022-03-02  1:44                     ` Lee Shallis
2022-02-23  1:19 ` 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:

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

  git send-email \ \ \ \ \

* 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

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).