...
This compliant solution protects all accesses of the flags with a mutex, thereby preventing any thread scheduling interleaving from occurring. In addition, the flags are declared volatile
to ensure that the compiler will not attempt to move operations on them outside the mutex. Finally, the flags are embedded in a union alongside a long
int, and a static assertion guarantees that the flags do not occupy more space than the long
. This prevents any data not checked by the mutex from being accessed or modified with the bit fields.
...