I am currently in a debate with another developer who assures me that the following C ++ statement is atom: < / P>
x | = 0x1; // is shared by several threads
In compiling with VC ++ 11 in release mode, it creates the following ASMB:
01121270 or dword Ptr ds: [1124430 h], 1
Other developers say that bit operations are atoms and are therefore securely secure, otherwise my experience with the Intel i7 processor says otherwise.
I thought writing a shared memory with a multicore processor is unsafe because the individual processor cache, but more research is done when it seems that something in order of memory functions between the x86 processor / core Guarantees that suggest that should be safe ... again, this is not what it seems like in my experience.
Since I do not have the official knowledge of these types of things, I am putting my case or I am sure that I am right.
No, it is definitely not guaranteed to be atomic. Whether it is implemented using a unit-vacuum directive (sequence) or not dependent on the compiler and platform. But from the standard standpoint, it is not atomic; So if a thread perfroms x | = 0x1;
and if the other thread reaches x
without a synchronization point, then this is an unspecified behavior (data race).
Support of quote from C ++ 11:
1.10 / 5:
The library operates on many atomic operations (clause 29) and mutes (Section 30), which are specifically identified as synchronization operations ...
std :: atomic
and related functions in Section 29 Has been introduced. It does not specify the basic type of atom.
1.10 / 21:
The execution of a program contains data races , if there is conflicting action in two different threads, of which There is at least one atom, and neither does any such data before the other in the race result undefined behavior. ...
No comments:
Post a Comment