Atomic load / storage for OSs other than BSD?

Among the atomic operations provided by the BSD (as indicated on the atomic page (9)), there are atomic_load_acq_int()and atomic_store_rel_int(). When looking for an equivalent for other OSs (for example, by reading the atom (3) man page for Mac OS X, atomic_ops (3C) man page for Solaris, and functions Interlocked*()for Windows), there seem to be no (obvious) equivalents for simple read / text recording int.

Is this because it is meant for those OSs that read / write for int, are guaranteed to be atomic by default? (Or should you use declare them volatilein C / C ++?)

If not, how to make atomic read / write inton these OS?

(Atomic readings can be modeled by returning the result of atomic addition of 0, but there is no equivalent for performing atomic writing.)

+3
source share
1 answer

I think you mix atomic memory access with cache coherency . The first one is the necessary hardware support for creating synchronization primitives in software (spin-locks, semaphores and mutexes), and the second is the hardware support for several chips (several processors and peripherals) operating on the same bus, and a consistent view main memory.

/ . , , GCC . compare-and-swap /store -conditional . , , -S GCC, , .

- - - , , , --.

aligned (- ). int , (. GCC builtins ).

. . , . - , , , . ( " " ) . , (, ), , ( ).

volatile . , . , " " .

. , .

Edit:

++ 0x, , concurrency, . Hans Boehm ++ .

+4

Source: https://habr.com/ru/post/1754109/


All Articles