Re: A question about "4.3.4.2 A Volatile Solution" of perfbook
Elad Lahav <[email protected]> Mon, 11 Nov 2024 07:04:52 -0500
| Newsgroups | org.kernel.vger.perfbook |
|---|---|
| Message-ID | <CAJbg=FVpjoBHHHTaYewTn-k-Dfa9LqmyZ2vPT7+b2Ep6Xi0xbg@mail.gmail.com> |
> Machine-sized means smaller than or equal to sizeof(long). > > Take a look at the implementation of WRITE_ONCE or READ_ONCE of linux. That is not necessarily true. What sizes and alignments are guaranteed to be atomic for access (i.e., writing a value to a memory location results in everyone seeing either the old value or the new value, never a mix) is defined by the hardware architecture, and need not align with the C definition of long. You can use the C11 ATOMIC_*_LOCK_FREE() to determine if a type is atomic. As Akira points out, the term "atomic" is overloaded, and can cause much confusion. A type being atomic for read or write access does not imply atomic read-modify-write. --Elad