How to understand the semantics of acquisition and release?

I discovered three functions from MSDN, below:

1.InterlockedDecrement().

2.InterlockedDecrementAcquire().

3.InterlockedDecrementRelease().

I knew that these functions are used to reduce the value as an atomic operation, but I do not know the difference between the three functions

+4
source share
2 answers

(um ... but don't ask me what that means for sure)

I'll take a hit on this.

It should be remembered that the compiler or the CPU itself can change the reading and writing order in memory if they do not interact with each other.

This is useful, for example, if you have code that possibly updates the structure:

if ( playerMoved ) {
  playerPos.X += dx;
  playerPos.Y += dy; 

  // Keep the player above the world surface.
  if ( playerPos.Z + dz > 0 ) {
     playerPos.Z += dz;
  }
  else {
     playerPos.Z = 0;
  }
}

, , , , Z , X Y, .

- , . , , , . , , , .

, , , "done", , "" .

. , , Acquire, , , , . , , Release, , , , .

- , .., , . , ( ), ( ).

, /, , . , - , , , , , . , , (, ), , .

Acquire " , ". " ". .

+5

http://preshing.com/20120913/acquire-and-release-semantics/

- , , read-modify-write . . - , .

- , , read-modify-write . -. write-release , .

(um... , )

+2

Source: https://habr.com/ru/post/1547094/


All Articles