本文整理汇总了C#中System.Threading.Mutex.Release方法的典型用法代码示例。如果您正苦于以下问题:C# Mutex.Release方法的具体用法?C# Mutex.Release怎么用?C# Mutex.Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Mutex
的用法示例。
在下文中一共展示了Mutex.Release方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetWaitQueueLength
public void TestGetWaitQueueLength()
{
Mutex sync = new Mutex();
AbstractQueuedSynchronizer.ConditionObject c = sync.NewCondition();
Pair data = new Pair(sync, c);
Thread t1 = new Thread(TestGetWaitQueueLengthRunnable1);
Thread t2 = new Thread(TestGetWaitQueueLengthRunnable2);
try
{
t1.Start(data);
Thread.Sleep(SHORT_DELAY_MS);
t2.Start(data);
Thread.Sleep(SHORT_DELAY_MS);
sync.Acquire(1);
Assert.IsTrue(sync.HasWaiters(c));
Assert.AreEqual(2, sync.GetWaitQueueLength(c));
c.SignalAll();
sync.Release(1);
Thread.Sleep(SHORT_DELAY_MS);
sync.Acquire(1);
Assert.IsFalse(sync.HasWaiters(c));
Assert.AreEqual(0, sync.GetWaitQueueLength(c));
sync.Release(1);
t1.Join(SHORT_DELAY_MS);
t2.Join(SHORT_DELAY_MS);
Assert.IsFalse(t1.IsAlive);
Assert.IsFalse(t2.IsAlive);
}
catch (Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:35,代码来源:AbstractQueuedSynchronizerTest.cs示例2: TestAwaitUntilTimeout
public void TestAwaitUntilTimeout()
{
Mutex sync = new Mutex();
AbstractQueuedSynchronizer.ConditionObject c = sync.NewCondition();
try
{
sync.Acquire(1);
DateTime deadline = DateTime.Now;
Assert.IsFalse(c.AwaitUntil(deadline.AddSeconds(5)));
sync.Release(1);
}
catch (Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:17,代码来源:AbstractQueuedSynchronizerTest.cs示例3: TestAwait
public void TestAwait()
{
Mutex sync = new Mutex();
AbstractQueuedSynchronizer.ConditionObject c = sync.NewCondition();
Pair data = new Pair(sync, c);
Thread t = new Thread(TestAwaitRunnable);
try
{
t.Start(data);
Thread.Sleep(SHORT_DELAY_MS);
sync.Acquire(1);
c.Signal();
sync.Release(1);
t.Join(SHORT_DELAY_MS);
Assert.IsFalse(t.IsAlive);
}
catch (Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:22,代码来源:AbstractQueuedSynchronizerTest.cs示例4: TestAcquireInterruptibly1
public void TestAcquireInterruptibly1()
{
Mutex sync = new Mutex();
sync.Acquire(1);
Thread t = new Thread(InterruptedSyncRunnable);
try
{
t.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
t.Interrupt();
Thread.Sleep(SHORT_DELAY_MS);
sync.Release(1);
t.Join();
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:20,代码来源:AbstractQueuedSynchronizerTest.cs示例5: TestAwaitTimeout
public void TestAwaitTimeout()
{
Mutex sync = new Mutex();
AbstractQueuedSynchronizer.ConditionObject c = sync.NewCondition();
try
{
sync.Acquire(1);
Assert.IsFalse(c.Await(SHORT_DELAY_MS) > 0);
sync.Release(1);
}
catch (Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:15,代码来源:AbstractQueuedSynchronizerTest.cs示例6: TestAcquireTimedTimeout
public void TestAcquireTimedTimeout()
{
Mutex sync = new Mutex();
sync.Acquire(1);
Thread t = new Thread(TestAcquireTimedTimeoutRunnable);
try
{
t.Start(sync);
t.Join();
sync.Release(1);
}
catch (Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:17,代码来源:AbstractQueuedSynchronizerTest.cs示例7: TestGetState
public void TestGetState()
{
Mutex sync = new Mutex();
sync.Acquire(1);
Assert.IsTrue(sync.AccessIsHeldExclusively());
sync.Release(1);
Assert.IsFalse(sync.AccessIsHeldExclusively());
Thread t = new Thread(TestGetStateRunnable);
try
{
t.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.AccessIsHeldExclusively());
t.Join();
Assert.IsFalse(sync.AccessIsHeldExclusively());
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:22,代码来源:AbstractQueuedSynchronizerTest.cs示例8: TestTryAcquireWhenSynced
public void TestTryAcquireWhenSynced()
{
Mutex sync = new Mutex();
sync.Acquire(1);
Thread t = new Thread(TestTryAcquireWhenSyncedRunnable);
try
{
t.Start(sync);
t.Join();
sync.Release(1);
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:17,代码来源:AbstractQueuedSynchronizerTest.cs示例9: TestGetSharedQueuedThreads
public void TestGetSharedQueuedThreads()
{
Mutex sync = new Mutex();
Thread t1 = new Thread(InterruptedSyncRunnable);
Thread t2 = new Thread(InterruptibleSyncRunnable);
try {
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
sync.Acquire(1);
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
t1.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
t2.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
t1.Interrupt();
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
sync.Release(1);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.SharedQueuedThreads.IsEmpty());
t1.Join();
t2.Join();
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:29,代码来源:AbstractQueuedSynchronizerTest.cs示例10: TestHasContended
public void TestHasContended()
{
Mutex sync = new Mutex();
Thread t1 = new Thread(InterruptedSyncRunnable);
Thread t2 = new Thread(InterruptibleSyncRunnable);
try
{
Assert.IsFalse(sync.HasContended);
sync.Acquire(1);
t1.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.HasContended);
t2.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.HasContended);
t1.Interrupt();
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.HasContended);
sync.Release(1);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsTrue(sync.HasContended);
t1.Join();
t2.Join();
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:29,代码来源:AbstractQueuedSynchronizerTest.cs示例11: TestGetFirstQueuedThread
public void TestGetFirstQueuedThread()
{
Mutex sync = new Mutex();
Thread t1 = new Thread(InterruptedSyncRunnable);
Thread t2 = new Thread(InterruptibleSyncRunnable);
try
{
Assert.IsNull(sync.FirstQueuedThread);
sync.Acquire(1);
t1.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.AreEqual(t1, sync.FirstQueuedThread);
t2.Start(sync);
Thread.Sleep(SHORT_DELAY_MS);
Assert.AreEqual(t1, sync.FirstQueuedThread);
t1.Interrupt();
Thread.Sleep(SHORT_DELAY_MS);
Thread.Sleep(SHORT_DELAY_MS);
Assert.AreEqual(t2, sync.FirstQueuedThread);
sync.Release(1);
Thread.Sleep(SHORT_DELAY_MS);
Assert.IsNull(sync.FirstQueuedThread);
t1.Join();
t2.Join();
}
catch(Exception e)
{
UnexpectedException(e);
}
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:30,代码来源:AbstractQueuedSynchronizerTest.cs示例12: TestTryAcquire
public void TestTryAcquire()
{
Mutex rl = new Mutex();
Assert.IsTrue(rl.AccessTryAcquire(1));
Assert.IsTrue(rl.AccessIsHeldExclusively());
rl.Release(1);
}
开发者ID:tabish121,项目名称:NMS.Pooled,代码行数:7,代码来源:AbstractQueuedSynchronizerTest.cs本文标签属性:
示例:示例图
代码:代码生成器