Wednesday, June 8, 2016

Why do we use interlocked classes?

Interlocked classes used to achieve synchronization in a multithreaded environment.
They are used for increament,decreament, compareExchange and Exchange values.

Actually increament of a number seems single step operation but it involve three steps.

1. Load value in register
2. Increament it
3. Assign it in variable.

Interlocked classes promised atomocity of all these three steps.
Interlocked classes are fast in comparison of lock statement.

No comments: