Hi All,
I'm trying to use bools to sync between two threads. I cant' use C++11 and I thought mutexes would be slightly heavy for this.
So, I do something like this:
// ==================================
// Thread A
.. do some stuff ..
// wait for signal.
while (!signalFromThreadB) {
pthread_yield();
}
.. do some more stuff.
// ==================================
// ==================================
// Thread B
.. do some stuff ..
signalFromThreadB = true
.. continue.
// ==================================
There is no other shared data between these two threads. Now questions:
I have declared signalFromThreadB as volatile bool
- Is the bool assignment guarenteed to be atomic?
- Is this fine for doing a sync or would I need to use mutexes to be safe?
Can anyone please explain?
Thanks!