SpinLock(Boolean) コンストラクター
定義
public:
SpinLock(bool enableThreadOwnerTracking);
public SpinLock (bool enableThreadOwnerTracking);
new System.Threading.SpinLock : bool -> System.Threading.SpinLock
Public Sub New (enableThreadOwnerTracking As Boolean)
パラメーター
- enableThreadOwnerTracking
- Boolean
デバッグのためにスレッド ID をキャプチャして使用するかどうか。Whether to capture and use thread IDs for debugging purposes.
例
次の例は、スピンロックの使用方法を示しています。The following example demonstrates how a SpinLock may be used.
// C#
public class MyType
{
private SpinLock _spinLock = new SpinLock();
public void DoWork()
{
bool lockTaken = false;
try
{
_spinLock.Enter(ref lockTaken);
// do work here protected by the lock
}
finally
{
if (lockTaken) _spinLock.Exit();
}
}
}
' Visual Basic
Class MyType
Private _spinLock As New SpinLock()
Public Sub DoWork()
Dim lockTaken As Boolean = False
Try
_spinLock.Enter(lockTaken)
' do work here protected by the lock
Finally
If lockTaken Then _spinLock.Exit()
End Try
End Sub
End Class
注釈
のパラメーターなしのSpinLockコンストラクターは、スレッドの所有権を追跡します。The parameterless constructor for SpinLock tracks thread ownership.