Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ReaderWriterLock::IsWriterLockHeld Property

 

Gets a value indicating whether the current thread holds the writer lock.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public:
property bool IsWriterLockHeld {
	bool get();
}

Property Value

Type: System::Boolean

true if the current thread holds the writer lock; otherwise, false.

The following code example demonstrates that when an attempt is made to acquire a reader lock on a thread that has a writer lock, ReaderWriterLock does not grant the reader lock but instead increments the lock count on the writer lock.

using namespace System;
using namespace System::Threading;
int main()
{
   ReaderWriterLock^ rwLock = gcnew ReaderWriterLock;
   rwLock->AcquireWriterLock( Timeout::Infinite );
   rwLock->AcquireReaderLock( Timeout::Infinite );
   if ( rwLock->IsReaderLockHeld )
   {
      Console::WriteLine( "Reader lock held." );
      rwLock->ReleaseReaderLock();
   }
   else
   if ( rwLock->IsWriterLockHeld )
   {
      Console::WriteLine( "Writer lock held." );
      rwLock->ReleaseWriterLock();
   }
   else
   {
      Console::WriteLine( "No locks held." );
   }


   if ( rwLock->IsReaderLockHeld )
   {
      Console::WriteLine( "Reader lock held." );
      rwLock->ReleaseReaderLock();
   }
   else
   if ( rwLock->IsWriterLockHeld )
   {
      Console::WriteLine( "Writer lock held." );
      rwLock->ReleaseWriterLock();
   }
   else
   {
      Console::WriteLine( "No locks held." );
   }
}

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft