Quantcast
Channel: How to atomically perform sequential load and store operations? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How to atomically perform sequential load and store operations?

$
0
0

Consider this code under GCC 4.8.0:

std::atomic<bool> a;std::atomic<bool> b;a.store( b.load() ); // want to be atomic

How can I make the line above to be atomic as whole? In other words, how to obtain atomic assignment of atomic variables?

Are there any alternatives for std::atomic which allow this?


I have found __transaction_atomic {/* any code goes here */} which is activated on GCC by -fgnu-tm. With this, one can write anything in the block and it will be performed atomically.

Now the question are:

Is __transaction_atomic implemented with mutexes? If yes, then what the mutex actually locks?

Does the implementation of __transaction_atomic change depending on what is in it's block? If yes, then how it changes?


Viewing all articles
Browse latest Browse all 3

Trending Articles