We all familiar with the lock in C#,
and we all know that we have to lock with an Object in order to distinguish between diffrent unrelated critical sections on the code like this:
class Account
{
decimal balance;
private Object thisLock = new Object();
public void Withdraw(decimal amount)
{
lock (thisLock)
{
if (amount > balance)
{
throw new Exception("Insufficient funds");
}
balance -= amount;
}
}
}
but does anyone knows how the C# class lock uses this unique object in order to lock and distinguish between locks? i've searched every where and tried to look my self at the type lock, but i couldn't find nothing.
does anyone knows the answer?