给定以下代码:
...
private static SpinLock logLock = new SpinLock(false);
...
private static void ThreadFunc()
{
bool lockTaken = false;
logLock.Enter(ref lockTaken)
{
try
{
// do stuff with during an acquired SpinLock
}
finally
{
logLock.Exit();
}
}
}
如果 Enter 块“失败”,因为它在获取锁时收到 false,那么当前线程是否像自旋锁一样旋转并等到它可以获取它,或者这个块只是被绕过并且该线程丢失了?
谢谢,
斯科特