I have a volatile bool 'play' flag in my class that is being set by one thread and being read by another thread.
Do I need to synchronize the calls to that flag? for example in this function:
void stop()
{
play = false;
}
In windows they have the _InterlockedExchange and OSX has OSAtomicAdd64Barrier, I've seen those functions being used with shared primitives, do I need them?
Thank you
Yes, and volatile does not in any way imply thread safe or atomic. Use std::mutex and std::unique_lock etc if you can, not the platform specifics. std::atomic is good choice -- maybe even best in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With