Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of Interlocked.Increment

Tags:

People also ask

What is interlocked increment?

The InterlockedIncrement function both increments (increases by one) the value of the specified 32-bit variable and checks the resulting value. The function prevents more than one thread from using the same variable simultaneously.

Is interlocked increment slow?

It is slower since it forces the action to occur atomically and it acts as a memory barrier, eliminating the processor's ability to re-order memory accesses around the instruction. You should be using Interlocked.

What is interlocked C#?

The methods of this class help protect against errors that can occur when the scheduler switches contexts while a thread is updating a variable that can be accessed by other threads, or when two threads are executing concurrently on separate processors.


Is Interlocked.Increment(ref x) faster or slower than x++ for ints and longs on various platforms?