I work with multethreading bug. Now I see that for some reason lock isn't executed even once but is locked. I have the next class:
public sealed class Foo
{
private readonly object _lock = new object();
private static ulong _inCnt = 0;
public void SomeMethod(ulong poo)
{
lock (_lock)
{
_inCnt++;
... [some code]
}
}
}
I paused all threads in the VS, inspected all of them and see that there is only one thread in the SomeMethod
and it is waiting for lock (_lock)
to be freed (_inCnt = 0)
.
I resumed threads, waited for a while, paused threads and see the same picture, the same (and only one) thread is still waiting for the lock (_lock)
in SomeMethod
and _inCnt
is zero!
But it will be one or more if lock will be ever entred(_inCnt++
is the first line after lock (_lock)
no exception can happens, we don't abort threads). How can it be zero and lock is locked?