Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between Java atomic integer and C# Interlocked.Increment method

Im just wondering, is there a difference between how you increment a static variable in Java and C# in an threaded enviroment?

In Java you use atomic int:s to make this operation and in C# you use Interlocked.Incement(ref yourVar)

I by this dont mean the code you write but how it is actually locks the memory and does the actual increment.

like image 368
Marthin Avatar asked May 27 '11 09:05

Marthin


1 Answers

Interlocked operation doest not lock memory, it rather emits LOCK prefix to the instruction depending on the operation. That cause processor to assert bus lock so only instruction is executed once. You can further look at the following article

like image 195
crypted Avatar answered Oct 15 '22 21:10

crypted