Reader Lock : ReaderWriterLock : Thread C# Examples


C# Examples » Thread » ReaderWriterLock »

 

Reader Lock









    
using  System;
using  System.Collections.Generic;
using  System.Diagnostics;
using  System.IO;
using  System.Reflection;
using  System.Runtime;
using  System.Runtime.CompilerServices;
using  System.Security;
using  System.Text;
using  System.Threading;

public  class  MainClass
{
        
        public  static  void  Main()
        {
              ReaderWriterLock  rwLock  =  new  ReaderWriterLock();

                rwLock.AcquireReaderLock(250);
                if  (!rwLock.IsReaderLockHeld)
                      return;

                Console.WriteLine("Reader  lock  held");
                
                LockCookie  cookie  =  rwLock.UpgradeToWriterLock(250);
                if  (rwLock.IsWriterLockHeld)
                {
                        Console.WriteLine("Upgraded  to  writer  lock");
                        rwLock.DowngradeFromWriterLock(ref  cookie);
                }

                rwLock.ReleaseReaderLock();

        }
}
    
   
  
   



Output

Reader lock held
Upgraded to writer lock


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» ReaderWriterLock