Block free constructions in .net

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

I searched a little and could not think of anything.

Blocking algorithms require some kind of CAS instruction, which is provided through the Unsafe undocumented class in Java, does .NET have anything equivalent?

+5
source share
5 answers

.NET has an Interlocked class with the static methods Interlocked.Increment () and Interlocked.Decrement ().

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

System.Threading och.

+6

.Net. , , , ..

RantPack

+4

, , (), .NET 4.0 CCR/TPL . TPL, , , ( ..).

.., Interlocked ..

0

, .net Interlocked class.

, . , .

.net, -

int counter;
void code(){
    myThreadVal = Interlocked.increment(counter);
}

, , myThreadVal.

java AtomicInteger , .

0

All Articles