4 ms·
Are you sure atomics can help in this case? EDIT: also, volatile is a bad idea, too, unless you are doing something low-level like a kernel or hacking on memor
by nsajko 7y ago
Are you sure atomics can help in this case?
EDIT: also, volatile is a bad idea, too, unless you are doing something low-level like a kernel or hacking on memory mapped IO pins. It does not synchronize accesses between threads.
- plorkyeran 7y agoC11 atomics include a memory barrier, so making need_to_stop atomic would indeed suffice.
- nybble41 7y agoIn addition to what plorkyeran said: While volatile alone doesn't synchronize accesses between threads, it is enough to ensure that the variable is read separately in each iteration of the loop—though it might just be read from the L1 cache and not take into account writes from other cores.