0
Answer

thread safety using Interlocked

George George

George George

16y
1.7k
1

Hello everyone,


Suppose Status is an int variable, which could be read and write by multiple threads.

When assign the value (write) of Status variable, I always use,

[Code]
Interlocked.Exchange(ref Status, SomeValue);
[/Code]

My question is, in order to make write/read of this variable thread safe, could I access (read) the variable directly by accessing Status variable, for example

[Code]
Console.write (Status);

if (Status > 0)
{
 // some ops
}
[/Code]


thanks in advance,
George