Quantcast
Channel: Volatile vs. Interlocked vs. lock - Stack Overflow
Viewing all articles
Browse latest Browse all 11

Answer by Michael Damatov for Volatile vs. Interlocked vs. lock

$
0
0

"volatile" does not replace Interlocked.Increment! It just makes sure that the variable is not cached, but used directly.

Incrementing a variable requires actually three operations:

  1. read
  2. increment
  3. write

Interlocked.Increment performs all three parts as a single atomic operation.


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>