Does the c# lock keyword use a \'yielding\', \'spin-locking\' or hybrid approach to handle contention?
So far my searches on the .net lock statement hasn\'t turned u
lock (obj)
{
}
was just syntactic sugar for Monitor.Enter in a try...finally.
Monitor.Enter(obj);
try
{
}
finally
{
Monitor.Exit(obj);
}
It is now something a little better (Thanks to Mark and Adriano for keeping me current).
bool locked = false;
try
{
Monitor.Enter(_syncRoot, ref locked);
}
finally
{
if (locked)
Monitor.Exit(_syncRoot);
}