samedi 28 février 2015

The nearest __sync_* alternative to acquire/release semantics?

I'm porting some C++ code to an earlier version of g++ which does not support atomic types (~g++ 4.2)


In my C++11 code, I would use acquire/release semantics to store atomic variables



atomic<int> a;
...
a.load(memory_order_acquire);
// Some operations on 'a'
a.store(new_val, memory_order_release);


Which __sync_* builtin would be the best replacement to the load/store option? I was thinking about using __sync_lock_test_and_set for the store, and __sync_lock_release for load, would this be sufficient?


Somewhat along the lines:



__sync_lock_release(a)
// Some ops on 'a'
__sync_lock_test_and_set(a,new_value);


(I'm trying to solve this without locks, if possible)


Aucun commentaire:

Enregistrer un commentaire