Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 23 Feb 2022 15:06:35 -0500
From: Rich Felker <>
To: Markus Wichmann <>
Subject: Re: Suggestion for thread safety

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.

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.