Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock free constructs in .net

I am new to .net and would like to know whether .net has the java equivalent of AtomicInteger, ConcurrentLinkedQueue, etc?

I did a bit of search and couldnt come up with anything.

The lock free algorithms need some sort of a CAS instruction, which is provided through the undocumented Unsafe class in Java, does .net have anything equivalent?

like image 520
pdeva Avatar asked Nov 29 '08 08:11

pdeva


1 Answers

In .NET there is the Interlocked class, with static methods Interlocked.Increment() and Interlocked.Decrement().

See http://msdn.microsoft.com/en-us/library/system.threading.interlocked.aspx.

You will also find other atomic och synchronization constructs in the System.Threading namespace.

like image 138
Tommy Avatar answered Nov 06 '22 03:11

Tommy