public static readonly object _locker = new object();
public static int _val1;
public int _val2 = 1;
public void Go()
if (_val2 != 0) Console.WriteLine (_val1 / _val2);
_val2 = 0;
In the above example is it possible for another thread to change the values of _val2 and _val1?
lock keyword locks only access to the code section, not the data used inside of it. This means that it is possible for another thread to modify both
_val2 even when the locked section is executed.
Hope this helps,
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)