Quote:
Simple reads and writes to properly-aligned 32-bit variables are atomic. In other words, when one thread is updating a 32-bit variable, you will not end up with only one portion of the variable updated; all 32 bits are updated in an atomic fashion. However, access is not guaranteed to be synchronized. If two threads are reading and writing from the same variable, you cannot determine if one thread will perform its read operation before the other performs its write operation.
I'm no stranger to synchronization methods and implementation, but low-level CPU behavior is not my expertise. However, this paragraph from the Platform SDK docs seems to contradict some of what I've been reading here, and maybe someone who knows more can enlighten us. In the case of a simple bool to flag a thread termination, the above paragraph seems to indicate that you can never get an "undefined" value. I believe the bool data type is implemented as a 32 bit quantity in MSVC, and assuming it was properly aligned, changing it from true to false or vice versa should be atomic without any special care taken.
As stated above, simple reads and writes, although atomic, do not guarantee sequence. A critical section wouldn't guarantee sequence either, just that only one thread could read or write the value at a time. Given the above paragraph, it seems that on 32-bit Intel chips, a critical section around a simple bool for flagging thread termination is redundant and unnecessary.
Anyway, just curious what you experts think about the above quote and how it relates to the current discussion.