c# - Does Interlocked.CompareExchange use a memory barrier? -


I am reading posts about Duffy, and I try to understand something about the previous code sample in the post I am:

  while (interlock .compressx exchange (ref I_State, 1, 0)! = 0); M_state = 0; While (Interlock Comprehensive Exchange (Ref I_State, 1, 0)! = 0); M_state = 0; ...  

The second CMPXG operation is executed, does it use memory constraints to ensure that the value of m_state actually writes the latest value has gone? Or will it just use some value which is already stored in the processor's cache? (Assume that m_state has not been declared as volatile).
If I understand correctly, if CMPXCH does not use memory hurdles, then the entire lock acquisition process will not be fair because it is very likely that the first thread to acquire the lock will be that All of the following locks will get . Do I understand correctly, or am I forgetting something here?

Edit : The main question is that the call to make comparison can cause memory constraints before attempting to read the value of Exchange M_State. So specifying 0 will be seen by all the threads, when they compare again, try to call x change.

Any X86 instruction that contains full memory in the lock prefix Interrupted as Abell's response has been shown, Interlocked * APIs and Comparison Exchange Lock - use previously guided instructions like lock cmpxchg . Therefore, this means the memory fence.

Yes, interlock The Comprex Exchange uses a memory barrier.

Why? Because the x86 processor did this, Intel 7.1.2.2:

For P6 family processors, locked operation serializes all outstanding loads and store operations < / Strong> (which are awaiting completion) This rule is also true with the exception of Pentium 4 and Intel Xen processors. Load operation that can not be sorted in a vulnerable memory type (such as WC memory type).

Unstable There is nothing to do with this discussion; it is about nuclear operations; In order to support the nuclear operations in the CPU, x86 guarantees all the previous loads and stores.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -