In my application, I have a block of shared memory, which one thread periodically writes to, and another thread periodically gets (and then sets to 0)
Thread 1:
@onevent:
__atomic_store(addr, val, __ATOMIC_SEQ_CST);
Thread 2:
while((val = __atomic_exchange_n(addr, 0, __ATOMIC_SEQ_CST)) == 0);
... work on val
I find that occasionally thread 2 spins forever. In addition, placing any kind of debugging statements, say a print statement of addr after the atomic store or after each atomic exchange, and everything works fine (so some kind of race condition).
I'm really stuck (since I tried this in a separate isolated program, and it seems to work fine). Any help would be much appreciated. For reference I am running on a high-core count dual-socket node.