Re: Suboptimal spinlock code due to volatile - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Suboptimal spinlock code due to volatile
Date
Msg-id CA+TgmoZ78ieZYsrxzB=D1YjjnV1FHFS97nxC+E+mZkouqBWuCg@mail.gmail.com
Whole thread Raw
In response to Re: Suboptimal spinlock code due to volatile  (Heikki Linnakangas <hlinnaka@iki.fi>)
List pgsql-hackers
On Tue, Jul 30, 2024 at 3:46 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
> Aside from performance, I find "volatile" difficult to reason about. I
> feel more comfortable with atomics and memory barriers.

I think nearly everyone feels more comfortable with atomics and memory
barriers. The semantics of volatile are terrible. It almost does more
or less than what you actually wanted, sometimes both.

Reading Andres's original message, I couldn't help wondering if this
is an argument against rolling our own spinlock implementations.
Presumably a compiler intrinsic wouldn't cause this kind of
unfortunate artifact. Our position in the past has essentially been
"we know better," but this seems like a counterexample.

--
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: New compiler warnings in buildfarm
Next
From: Ranier Vilela
Date:
Subject: Re: New compiler warnings in buildfarm