當前位置: 首頁>>代碼示例>>C#>>正文


C# ReaderWriterLock.ReleaseWriterLock方法代碼示例

本文整理匯總了C#中System.Threading.ReaderWriterLock.ReleaseWriterLock方法的典型用法代碼示例。如果您正苦於以下問題:C# ReaderWriterLock.ReleaseWriterLock方法的具體用法?C# ReaderWriterLock.ReleaseWriterLock怎麽用?C# ReaderWriterLock.ReleaseWriterLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Threading.ReaderWriterLock的用法示例。


在下文中一共展示了ReaderWriterLock.ReleaseWriterLock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: getOneCell

        public static string getOneCell()
        {
            string encodedOrder=null;
             readSem.WaitOne();// wait until buffer cell is not empty then only read
            ReaderWriterLock rw=new ReaderWriterLock();
            rw.AcquireWriterLock(Timeout.Infinite);
            try{
            //reading from buffer --- ciruclar queue

            if (front_read == bufferSize - 1)
                 front_read = 0;
            else
                 {

                     front_read = front_read + 1;
                  }
               encodedOrder = buffer[front_read];
               buffer[front_read] = string.Empty;
               String[] arr=encodedOrder.Split('#');
               Console.WriteLine("  chicken farm got an order from {0} of {1} chicken",arr[0],arr[2]);
            }
            catch (Exception e){ Console.WriteLine(""); }
            finally
            {
            rw.ReleaseWriterLock();
            writeSem.Release();

            }

            return encodedOrder;
        }
開發者ID:jvutukur,項目名稱:DistributedSoftwareDevelopmentProject,代碼行數:31,代碼來源:MultiBufferCell.cs

示例2: TestIsWriterLockHeld

		public void TestIsWriterLockHeld ()
		{
			rwlock = new ReaderWriterLock ();
			Assert.IsTrue (!rwlock.IsWriterLockHeld, "#1");
			rwlock.AcquireWriterLock (500);
			Assert.IsTrue (rwlock.IsWriterLockHeld, "#2");
			RunThread (new ThreadStart (IsWriterLockHeld_2));
			rwlock.ReleaseWriterLock ();
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:9,代碼來源:ReaderWriterLockTest.cs

示例3: LockVSReaderWriterLockVSReaderWriterLockSlimVSHandle

		public void LockVSReaderWriterLockVSReaderWriterLockSlimVSHandle()
		{
			TestName("Lock vs. ReaderWriterLock vs. ReaderWriterLockSlim vs. Handle-based");

			Object o = new Object();
			
			CodeTimer.Time("Lock perf: Monitor", iterations,
			   () =>
			   {
				   Monitor.Enter(o);
				   //
				   Monitor.Exit(o);
			   });

			CodeTimer.Time("Lock perf: Lock", iterations,
			   () =>
			   {
				   lock (o)
				   {
				   }
				  
			   });

			ReaderWriterLockSlim rwls = new ReaderWriterLockSlim();
			CodeTimer.Time("Lock perf: ReaderWriterLockSlim", iterations,
			   () =>
			   {
				   rwls.EnterWriteLock();
				   rwls.ExitWriteLock();
			   });

			ReaderWriterLock rwl = new ReaderWriterLock();
			CodeTimer.Time("Lock perf: ReaderWriterLock", iterations,
			   () =>
			   {
				   rwl.AcquireWriterLock(Timeout.Infinite);
				   rwl.ReleaseWriterLock();
			   });

			Mutex mutex = new Mutex();
			CodeTimer.Time("Lock perf: Mutex", iterations,
			   () =>
			   {
				   mutex.WaitOne();
				   mutex.ReleaseMutex();
			   });
		}
開發者ID:denisefan28,項目名稱:Wind,代碼行數:47,代碼來源:ThreadingPerformanceTest.cs

示例4: PurgeCache

        protected override void PurgeCache(object sender, System.Timers.ElapsedEventArgs e)
        {
            ReaderWriterLock readWriteLock = new ReaderWriterLock();
            //Öncelik olarak ortanın altında seçiyoruz. Çünkü öncelik ekleme, güncelleme gibi işlerde.
            //Varsın bi kaç saniye geç temizlensin cache
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
            if (!Monitor.TryEnter(isPurging))
                return;

            try
            {
                readWriteLock.AcquireWriterLock(500);
                try
                {
                    List<object> expiredItems = new List<object>();

                    foreach (CacheKey timedKey in timedStorage.Keys)
                    {
                        if (timedKey.ExpirationDate < e.SignalTime)
                        {
                            // Temizlenmesi için birnevi nesneler işaretlenir.
                            expiredItems.Add(timedKey.Key);
                        }
                        else
                            break;
                    }

                    foreach (object key in expiredItems)
                    {
                        CacheKey timedKey = timedStorageIndex[key];
                        timedStorageIndex.Remove(timedKey.Key);
                        timedStorage.Remove(timedKey);
                    }
                }
                catch (ApplicationException ae)
                {
                    System.Console.WriteLine("Şu an lock lı.");
                }
                finally
                {
                    readWriteLock.ReleaseWriterLock();
                }
            }
            finally { Monitor.Exit(isPurging); }
        }
開發者ID:erdonet,項目名稱:FrameworkWithDesingPatterns,代碼行數:45,代碼來源:ExpritionMemCache.cs

示例5: setOneCell

        public static void setOneCell(string encodedObject)
        {
            writeSem.WaitOne(); //wait until buffer has atleast one space in it
            ReaderWriterLock rw = new ReaderWriterLock();
            rw.AcquireWriterLock(Timeout.Infinite);
            try{      // writing into buffer --- circular queue
                if(rear_write==bufferSize-1)
                    rear_write=0;
                else
                    rear_write=rear_write+1;

                buffer[rear_write]=encodedObject;

            }
            finally
            {
                rw.ReleaseWriterLock();
                readSem.Release();
            }
        }
開發者ID:jvutukur,項目名稱:DistributedSoftwareDevelopmentProject,代碼行數:20,代碼來源:MultiBufferCell.cs

示例6: TestAcquireLocks

		public void TestAcquireLocks ()
		{
			rwlock = new ReaderWriterLock ();
			rwlock.AcquireReaderLock (500);
			rwlock.AcquireReaderLock (500);
			rwlock.ReleaseReaderLock ();
				Assert.IsTrue (rwlock.IsReaderLockHeld, "#1");			
			RunThread (new ThreadStart (AcquireLock_readerWorks));
			Assert.IsTrue (rwlock.IsReaderLockHeld);
			
			RunThread (new ThreadStart (AcquireLock_writerFails));
			rwlock.ReleaseReaderLock ();
			Assert.IsTrue (!rwlock.IsReaderLockHeld);
			
			RunThread (new ThreadStart (AcquireLock_writerWorks));
			
			rwlock.AcquireWriterLock (200);
			RunThread (new ThreadStart (AcquireLock_writerFails));
			RunThread (new ThreadStart (AcquireLock_readerFails));
			rwlock.ReleaseWriterLock ();
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:21,代碼來源:ReaderWriterLockTest.cs

示例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);
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:22,代碼來源:ReaderWriterLockTest.cs

示例8: TestReleaseRestoreWriterLock

		public void TestReleaseRestoreWriterLock ()
		{
			rwlock = new ReaderWriterLock ();
			rwlock.AcquireWriterLock (500);
			rwlock.AcquireWriterLock (500);
			Assert.IsTrue (rwlock.IsWriterLockHeld);
			
			LockCookie co = rwlock.ReleaseLock ();
			RunThread (new ThreadStart (AcquireLock_readerWorks));
			
			rwlock.RestoreLock (ref co);
			RunThread (new ThreadStart (AcquireLock_readerFails));
			
			rwlock.ReleaseWriterLock ();
			Assert.IsTrue (rwlock.IsWriterLockHeld);
			rwlock.ReleaseWriterLock ();
			Assert.IsTrue (!rwlock.IsWriterLockHeld);
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:18,代碼來源:ReaderWriterLockTest.cs

示例9: AcquireWriterLock

 public static IDisposable AcquireWriterLock(ReaderWriterLock rwl)
 {
     rwl.AcquireWriterLock(Timeout.Infinite);
     return new Disposer(() => rwl.ReleaseWriterLock());
 }
開發者ID:Zoumaho,項目名稱:Backload,代碼行數:5,代碼來源:StreamWriterCache.cs

示例10: 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 });
        }
開發者ID:olachan,項目名稱:PostSharp-Toolkits,代碼行數:41,代碼來源:DetectDeadlocksTests.cs

示例11: 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);
        }
開發者ID:olachan,項目名稱:PostSharp-Toolkits,代碼行數:23,代碼來源:DetectDeadlocksTests.cs

示例12: TestIsWriterLockHeld

		public void TestIsWriterLockHeld ()
		{
			rwlock = new ReaderWriterLock ();
			Assert ("a1", !rwlock.IsWriterLockHeld);
			rwlock.AcquireWriterLock (500);
			Assert ("a2", rwlock.IsWriterLockHeld);
			RunThread (new ThreadStart (IsWriterLockHeld_2));
			rwlock.ReleaseWriterLock ();
		}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:9,代碼來源:ReaderWriterLockTest.cs

示例13: 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);
		}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:22,代碼來源:ReaderWriterLockTest.cs

示例14: WithWriteLockTimeoutWithExceptionTest

 public void WithWriteLockTimeoutWithExceptionTest()
 {
     var l = new ReaderWriterLock();
     var e = new AutoResetEvent(false);
     var lockGetted = false;
     var t = new Thread(() =>
     {
         var b = false;
         try
         {
             l.WithWriteLock(() =>
             {
                 lockGetted = true;
                 Assert.IsTrue(l.IsWriterLockHeld);
                 throw new InvalidOperationException();
             }, TimeSpan.FromSeconds(5));
         }
         catch (InvalidOperationException)
         {
             b = true;
         }
         Assert.IsTrue(b);
         e.Set();
     });
     l.AcquireWriterLock(100);
     t.Start();
     Thread.Sleep(1000);
     Assert.IsFalse(lockGetted);
     l.ReleaseWriterLock();
     e.WaitOne();
     Assert.IsTrue(lockGetted);
     Assert.IsFalse(l.IsWriterLockHeld);
 }
開發者ID:sergey-prokofiev,項目名稱:sp-tools,代碼行數:33,代碼來源:DisposableExtensionsTests.cs

示例15: WithWriteLockTimeoutSuccessTest

 public void WithWriteLockTimeoutSuccessTest()
 {
     var l = new ReaderWriterLock();
     var e = new AutoResetEvent(false);
     var lockGetted = false;
     var t = new Thread(() =>
     {
         l.WithWriteLock(() =>
         {
             lockGetted = true;
             Assert.IsTrue(l.IsWriterLockHeld);
         }, TimeSpan.FromSeconds(5));
         e.Set();
     });
     l.AcquireWriterLock(100);
     t.Start();
     Thread.Sleep(1000);
     Assert.IsFalse(lockGetted);
     l.ReleaseWriterLock();
     e.WaitOne();
     Assert.IsTrue(lockGetted);
     Assert.IsFalse(l.IsWriterLockHeld);
 }
開發者ID:sergey-prokofiev,項目名稱:sp-tools,代碼行數:23,代碼來源:DisposableExtensionsTests.cs


注:本文中的System.Threading.ReaderWriterLock.ReleaseWriterLock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。