当前位置: 首页>>代码示例>>C#>>正文


C# ReaderWriterLock.DowngradeFromWriterLock方法代码示例

本文整理汇总了C#中System.Threading.ReaderWriterLock.DowngradeFromWriterLock方法的典型用法代码示例。如果您正苦于以下问题:C# ReaderWriterLock.DowngradeFromWriterLock方法的具体用法?C# ReaderWriterLock.DowngradeFromWriterLock怎么用?C# ReaderWriterLock.DowngradeFromWriterLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.ReaderWriterLock的用法示例。


在下文中一共展示了ReaderWriterLock.DowngradeFromWriterLock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:55,代码来源:ReaderWriterLockTest.cs

示例2: UpgradeToWriterLock

 public static IDisposable UpgradeToWriterLock(ReaderWriterLock rwl)
 {
     var lockCookie = rwl.UpgradeToWriterLock(Timeout.Infinite);
     return new Disposer(() => rwl.DowngradeFromWriterLock(ref lockCookie));
 }
开发者ID:Zoumaho,项目名称:Backload,代码行数:5,代码来源:StreamWriterCache.cs

示例3: 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);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:ReaderWriterLockTest.cs

示例4: ExecuteJob

 /// <summary>
 /// Executes a job on demand, rather than waiting for its regularly scheduled time.
 /// </summary>
 /// <param name="job">The job to be executed.</param>
 public static void ExecuteJob(JobBase job)
 {
     ReaderWriterLock rwLock = new ReaderWriterLock();
     try
     {
         rwLock.AcquireReaderLock(Timeout.Infinite);
         if (job.Executing == false)
         {
             LockCookie lockCookie = rwLock.UpgradeToWriterLock(Timeout.Infinite);
             try
             {
                 if (job.Executing == false)
                 {
                     job.Executing = true;
                     QueueJob(job);
                 }
             }
             finally
             {
                 rwLock.DowngradeFromWriterLock(ref lockCookie);
             }
         }
     }
     finally
     {
         rwLock.ReleaseReaderLock();
     }
 }
开发者ID:SolidSnake74,项目名称:SharpCore,代码行数:32,代码来源:Scheduler.cs


注:本文中的System.Threading.ReaderWriterLock.DowngradeFromWriterLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。