本文整理汇总了C#中System.Threading.ReaderWriterLock.ReleaseReaderLock方法的典型用法代码示例。如果您正苦于以下问题:C# ReaderWriterLock.ReleaseReaderLock方法的具体用法?C# ReaderWriterLock.ReleaseReaderLock怎么用?C# ReaderWriterLock.ReleaseReaderLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ReaderWriterLock
的用法示例。
在下文中一共展示了ReaderWriterLock.ReleaseReaderLock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIsReaderLockHeld
public void TestIsReaderLockHeld ()
{
rwlock = new ReaderWriterLock ();
Assert ("a1", !rwlock.IsReaderLockHeld);
rwlock.AcquireReaderLock (500);
Assert ("a2", rwlock.IsReaderLockHeld);
RunThread (new ThreadStart (IsReaderLockHeld_2));
rwlock.ReleaseReaderLock ();
}
示例2: TestIsReaderLockHeld
public void TestIsReaderLockHeld ()
{
rwlock = new ReaderWriterLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld, "#1");
rwlock.AcquireReaderLock (500);
Assert.IsTrue (rwlock.IsReaderLockHeld, "#1");
RunThread (new ThreadStart (IsReaderLockHeld_2));
rwlock.ReleaseReaderLock ();
}
示例3: DowngradeTest
public void DowngradeTest ()
{
LockCookie lc1, lc2, lc3, lc4;
rwlock = new ReaderWriterLock ();
rwlock.AcquireReaderLock (Timeout.Infinite);
lc1 = rwlock.UpgradeToWriterLock (Timeout.Infinite);
rwlock.AcquireReaderLock (Timeout.Infinite);
lc2 = rwlock.UpgradeToWriterLock (Timeout.Infinite);
rwlock.AcquireReaderLock (Timeout.Infinite);
lc3 = rwlock.UpgradeToWriterLock (Timeout.Infinite);
rwlock.AcquireReaderLock (Timeout.Infinite);
lc4 = rwlock.UpgradeToWriterLock (Timeout.Infinite);
rwlock.DowngradeFromWriterLock (ref lc2);
Assert.IsFalse (rwlock.IsReaderLockHeld, "A1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "A2");
rwlock.ReleaseReaderLock ();
Assert.IsFalse (rwlock.IsReaderLockHeld, "B1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "B2");
rwlock.DowngradeFromWriterLock (ref lc4);
Assert.IsFalse (rwlock.IsReaderLockHeld, "C1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "C2");
rwlock.ReleaseReaderLock ();
Assert.IsFalse (rwlock.IsReaderLockHeld, "D1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "D2");
rwlock.DowngradeFromWriterLock (ref lc3);
Assert.IsFalse (rwlock.IsReaderLockHeld, "E1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "E2");
rwlock.ReleaseReaderLock ();
Assert.IsFalse (rwlock.IsReaderLockHeld, "F1");
Assert.IsTrue (rwlock.IsWriterLockHeld, "F2");
rwlock.DowngradeFromWriterLock (ref lc1);
Assert.IsTrue (rwlock.IsReaderLockHeld, "G1");
Assert.IsFalse (rwlock.IsWriterLockHeld, "G2");
rwlock.ReleaseReaderLock ();
Assert.IsFalse (rwlock.IsReaderLockHeld, "H1");
Assert.IsFalse (rwlock.IsWriterLockHeld, "H2");
}
示例4: TestBug_55909
public void TestBug_55909 ()
{
rwlock = new ReaderWriterLock ();
ThreadRunner tr = StartThread (new ThreadStart(Bug_55909_Thread2));
Thread.Sleep (200);
rwlock.AcquireReaderLock (Timeout.Infinite);
try {
LockCookie lc = rwlock.UpgradeToWriterLock (Timeout.Infinite);
Thread.Sleep (500);
}
finally { rwlock.ReleaseReaderLock(); }
tr.Join ();
}
示例5: TestBug_55911
public void TestBug_55911 ()
{
rwlock = new ReaderWriterLock ();
rwlock.AcquireReaderLock (Timeout.Infinite);
try {
LockCookie lc = rwlock.UpgradeToWriterLock (Timeout.Infinite);
}
finally { rwlock.ReleaseReaderLock(); }
rwlock.AcquireReaderLock (Timeout.Infinite);
try {
LockCookie lc = rwlock.UpgradeToWriterLock (Timeout.Infinite);
}
finally { rwlock.ReleaseReaderLock(); }
}
示例6: TestReaderMustWaitWriter
public void TestReaderMustWaitWriter ()
{
// A thread cannot get the reader lock if there are other threads
// waiting for the writer lock.
rwlock = new ReaderWriterLock ();
rwlock.AcquireWriterLock (200);
ThreadRunner tr = StartThread (new ThreadStart (ReaderMustWaitWriter_2));
Thread.Sleep (200);
RunThread (new ThreadStart (AcquireLock_readerFails));
rwlock.ReleaseReaderLock ();
tr.Join ();
}
示例7: TestReaderInsideWriter
public void TestReaderInsideWriter ()
{
// Reader acquires and releases work like the writer equivalent
rwlock = new ReaderWriterLock ();
rwlock.AcquireWriterLock (-1);
rwlock.AcquireReaderLock (-1);
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (rwlock.IsWriterLockHeld);
rwlock.AcquireReaderLock (-1);
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (rwlock.IsWriterLockHeld);
rwlock.ReleaseWriterLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (rwlock.IsWriterLockHeld);
rwlock.ReleaseReaderLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (rwlock.IsWriterLockHeld);
rwlock.ReleaseReaderLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (!rwlock.IsWriterLockHeld);
}
示例8: TestUpgradeDowngradeLock
public void TestUpgradeDowngradeLock ()
{
rwlock = new ReaderWriterLock ();
rwlock.AcquireReaderLock (200);
rwlock.AcquireReaderLock (200);
LockCookie co = rwlock.UpgradeToWriterLock (200);
Assert.IsTrue (!rwlock.IsReaderLockHeld);
Assert.IsTrue (rwlock.IsWriterLockHeld);
RunThread (new ThreadStart (AcquireLock_writerFails));
rwlock.DowngradeFromWriterLock (ref co);
Assert.IsTrue (rwlock.IsReaderLockHeld);
Assert.IsTrue (!rwlock.IsWriterLockHeld);
RunThread (new ThreadStart (AcquireLock_readerWorks));
rwlock.ReleaseReaderLock ();
Assert.IsTrue (rwlock.IsReaderLockHeld);
rwlock.ReleaseReaderLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld);
}
示例9: GetWebDomainData
//- @GetWebDomainData -//
/// <summary>
/// Returns the WebDomainData object for a particular web domain.
/// </summary>
/// <param name="webDomainName">The web domain name used to lookup the web domain.</param>
/// <returns>A WebDomainData object or null if the web domain name is invalid.</returns>
public static WebDomainData GetWebDomainData(String webDomainName)
{
var readerWriterLock = new ReaderWriterLock();
readerWriterLock.AcquireReaderLock(Timeout.Infinite);
try
{
if (String.IsNullOrEmpty(webDomainName))
{
webDomainName = "root";
}
//+
return WebDomainDataList.AllWebDomainData.SingleOrDefault(p => p.Name == webDomainName);
}
finally
{
readerWriterLock.ReleaseReaderLock();
}
}
示例10: FindFirstMatch
internal virtual RewriteRule FindFirstMatch(HttpApplication app, out string requestUrl, RewriteRuleCollection rules, ReaderWriterLock ruleCollectionLock)
{
requestUrl = null;
RewriteRule matchedRule = null;
ruleCollectionLock.AcquireReaderLock(0);
try
{
foreach (var rule in rules)
{
if ((rule.Rewrite & RewriteOption.Domain) != 0)
requestUrl = app.Request.Url.AbsoluteUri;
else
requestUrl = app.Request.RawUrl;
if (rule.IsRewrite(requestUrl))
{
matchedRule = rule;
break;
}
}
}
finally
{
ruleCollectionLock.ReleaseReaderLock();
}
return matchedRule;
}
示例11: AcquireReaderLock
public static IDisposable AcquireReaderLock(ReaderWriterLock rwl)
{
rwl.AcquireReaderLock(Timeout.Infinite);
return new Disposer(() => rwl.ReleaseReaderLock());
}
示例12: ReaderWriter_WhenUpgradedWriteLockReleased_EdgesDeleteFromGraph
public void ReaderWriter_WhenUpgradedWriteLockReleased_EdgesDeleteFromGraph()
{
ReaderWriterLock rwl = new ReaderWriterLock();
Barrier barrier = new Barrier(3);
Barrier barrier2 = new Barrier(3);
Task t1 = new Task(() =>
{
rwl.AcquireReaderLock(Timeout.Infinite);
rwl.UpgradeToWriterLock(Timeout.Infinite);
rwl.ReleaseWriterLock();
barrier.SignalAndWait();
barrier2.SignalAndWait();
lock (rwl)
{
Thread.Sleep(100);
}
});
Task t2 = new Task(() =>
{
barrier.SignalAndWait();
lock (rwl)
{
barrier2.SignalAndWait();
rwl.AcquireWriterLock(Timeout.Infinite);
}
});
t1.Start();
t2.Start();
barrier.SignalAndWait();
rwl.AcquireReaderLock(Timeout.Infinite);
barrier2.SignalAndWait();
Thread.Sleep(500);
rwl.ReleaseReaderLock();
Task.WaitAll(new[] { t1, t2 });
}
示例13: ReaderWriter_When2CycleDetected_DoesNotThrows
public void ReaderWriter_When2CycleDetected_DoesNotThrows()
{
ReaderWriterLock rwl = new ReaderWriterLock();
Barrier barrier = new Barrier(2);
Action t1 = () =>
{
rwl.AcquireReaderLock(Timeout.Infinite);
barrier.SignalAndWait();
rwl.UpgradeToWriterLock(Timeout.Infinite);
rwl.ReleaseWriterLock();
};
Action t2 = () =>
{
rwl.AcquireReaderLock(Timeout.Infinite);
barrier.SignalAndWait();
Thread.Sleep(500);
rwl.ReleaseReaderLock();
};
TestHelpers.InvokeSimultaneouslyAndWait(t1, t2);
}
示例14: TestReaderInsideWriter
public void TestReaderInsideWriter ()
{
// Reader acquires and releases work like the writer equivalent
rwlock = new ReaderWriterLock ();
rwlock.AcquireWriterLock (-1);
rwlock.AcquireReaderLock (-1);
Assert ("u1", !rwlock.IsReaderLockHeld);
Assert ("u2", rwlock.IsWriterLockHeld);
rwlock.AcquireReaderLock (-1);
Assert ("u3", !rwlock.IsReaderLockHeld);
Assert ("u4", rwlock.IsWriterLockHeld);
rwlock.ReleaseWriterLock ();
Assert ("u5", !rwlock.IsReaderLockHeld);
Assert ("u6", rwlock.IsWriterLockHeld);
rwlock.ReleaseReaderLock ();
Assert ("u7", !rwlock.IsReaderLockHeld);
Assert ("u8", rwlock.IsWriterLockHeld);
rwlock.ReleaseReaderLock ();
Assert ("u9", !rwlock.IsReaderLockHeld);
Assert ("u10", !rwlock.IsWriterLockHeld);
}
示例15: TestReleaseRestoreReaderLock
public void TestReleaseRestoreReaderLock ()
{
rwlock = new ReaderWriterLock ();
rwlock.AcquireReaderLock (500);
rwlock.AcquireReaderLock (500);
Assert.IsTrue (rwlock.IsReaderLockHeld);
LockCookie co = rwlock.ReleaseLock ();
RunThread (new ThreadStart (AcquireLock_writerWorks));
rwlock.RestoreLock (ref co);
RunThread (new ThreadStart (AcquireLock_writerFails));
rwlock.ReleaseReaderLock ();
Assert.IsTrue (rwlock.IsReaderLockHeld);
rwlock.ReleaseReaderLock ();
Assert.IsTrue (!rwlock.IsReaderLockHeld);
}