c++ - Compare and exchange weak an atomic variable -
i have code (updated correct union-struct ordering):
union { struct { short b; short c; }; std::atomic<int> d; }
and want swap both b , c (hence atomic d) value zero, using compare_exchange_weak()
. have this:
a a; . . . std::atomic<int32_t> x = a.d.load(std::memory_order_relaxed); int32_t valtoreplace = 0; return a.d.compare_exchange_weak(valtoreplace, x, std::memory_order_release, std::memory_order_relaxed);
how do this? argument compare_exchange_weak(), x
, cannot atomic- confused?
the local variable x
shouldn't atomic. there's no reason be, , can't used argument compare_exchange_weak
, expects regular value.
i won't comment on whatever you're trying union, since makes no sense me.
Comments
Post a Comment