The simple answer is that the code above can cause problems when accessing multiple threads at the same time.
The .Net framework provides two solutions: blocking and thread synchronization.
(.. ints) .
, (Increment and Decrement), :
IncrementCount CrossRoads:
public void IncrementCount() {
Interlocked.Increment(ref _timeouts);
}
:
public void TimeIsUp(CrossRoads crossRoads){
crossRoads.IncrementCount();
}
, 64- 32- , . . Interlocked.Read method.
( # SyncLock VB.Net).
, (, ), () :
private static object SynchronizationObject = new Object();
public void PerformSomeCriticalWork()
{
lock (SynchronizationObject)
{
}
}