Bruno Haible <[email protected]> writes:

> Paul Eggert wrote:
>> > Storing the same value in the same location (of
>> > type 'int') is OK not only on those platforms where an 'int' access is 
>> > atomic,
>> > but even on architectures (such as m68k) where it isn't.
>> 
>> This variable is 'long', not 'int'.
>
> Oops, right. But anyway, 'long' is the size of a machine word, and except
> on m68k, for aligned accesses, loads and stores of such words are atomic.

Please don't make assumptions like these when there are better
alternatives.

Such assumptions are sources of endless and hard-to-find bugs.

There's no reason to assume loads and stores of such words compile down
to the loads and stores in hardware of the same kind you're thinking of.

This is _only_ guaranteed if using atomic accesses (whether through
atomic/sync builtins or stdatomic or even inline 'asm').  If anything,
such reasoning should encourage you *to* use atomic accesses, not to
abstain from using them, as they lack bugs while likely compiling down
to exactly the same code.
-- 
Arsen Arsenović

Attachment: signature.asc
Description: PGP signature

Reply via email to