I know that the bit field depends on the compiler, but I did not find the thread safety documentation in the bit field with the latest versions of g ++ and Visual C ++ 2010.
Are atoms active in a bitfield element?
"Safe thread", unfortunately, is very overloaded in programming.
If you mean atomic access to bit fields, the answer will not (at least on all processors that I know of). You have atomic access to 32-bit memory cells on 32-bit machines, but this means that you will read or write an integer 32-bit value. This does not mean that another thread will not do the same. If you want to stop, you probably want to sync.
If you mean synchronized access to bit fields, the answer is also absent unless you wrap your access in a higher-level synchronization primitive (which is often built on atomic operations).
, .
?
: Dr. , UOregon CS.
- , ( ) ( ) Undefined , , . , Undefined .
-, , 32- , CompareExchange:
, 2-4 . , , CompareExchange 5 , , , 2-4 , CompareExchange .
- , - int . ( ).
int
. Windows
. SO
atom.AddInt32 :
atomic.AddInt32(&intval, 1 << 0) //set the first bit atomic.AddInt32(&intval, 1 << 1) //set the second bit atomic.AddInt32(&intval, -(1 << 1 + 1 << 0)) //clear the first and second bit
Go, , ++ atom.AddInt32