multithreading - Compatibility between atomic operations in different C libraries -
a classical synchronization idiom between 2 threads (producer , consumer) involves
a producer updating value in shared memory (global_variable
), , updating atomic flag (flag
) release semantics. in c11 producer code written follows:
global_variable = 0; atomic_store_explicit(&flag, 1, memory_order_release); // flag integer
a consumer waiting value of flag
become 1, , reading global_variable
. if consumer has been written using gcc atomic library like:
while (__atomic_load_n(&flag, __atomic_acquire) != 1; // loop until flag enabled // read value of global_variable
if consumer code written using explicit c11 atomic loads expect programme correct...but gcc "equivalent" code guaranteed work too? in other words, question becomes: atomic operations defined in different libraries compatible? gcc atomics documentation vague respect:
the next built-in functions approximately match requirements c++11 memory model
c multithreading gcc atomic c11
No comments:
Post a Comment