CSharpTest.Net
WaitForExclusive Method
See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Synchronization Namespace > SimpleReadWriteLocking Class : WaitForExclusive Method

targetReaders
millisecondsTimeout

Glossary Item Box

This is the only real work to be done, once we've acquired the write lock we have to wait for all readers to complete. If/when that happens we can then own the write lock. The case where this does not take place is when a thread that already owns the lock calls us to lock again. In this case we can just return success and ignore the outstanding read requests. The major problem with this approach is that if function A() does a read-lock and calls function B() which does a write lock, this will fail. So the solution is to either use the upgradeable version (see the derived class UpgradableReadWriteLocking) and upgrade, or to start with a write lock in function A().

Syntax

Visual Basic (Declaration) 
Protected Function WaitForExclusive( _
   ByVal targetReaders As Integer, _
   ByVal millisecondsTimeout As Integer _
) As Boolean
C# 
protected bool WaitForExclusive( 
   int targetReaders,
   int millisecondsTimeout
)

Parameters

targetReaders
millisecondsTimeout

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys