Hello everyone. Up to this point I used lock(object) construction for acces to shared variables. After reading msdn article about Interlocked
The Increment and Decrement methods increment or decrement a variable and store the resulting value in a single operation. On most computers, incrementing a variable is not an atomic operation, requiring the following steps:
Load a value from an instance variable into a register.
Increment or decrement the value.
Store the value in the instance variable.
If you do not use Increment and Decrement, a thread can be preempted after executing the first two steps. Another thread can then execute all three steps. When the first thread resumes execution, it overwrites the value in the instance variable, and the effect of the increment or decrement performed by the second thread is lost.
I figure out that lock can fail my programm potentially:)
Are my decisions correct ?
p.s ssory for bad english(