Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

ReaderWriterLock

Synopsis

This class defines a lock that allows multiple readers, but only one writer. A thread can acquire a lock by calling AcquireReaderLock( ) or AcquireWriterLock( ). ReleaseReaderLock( ) and ReleaseWriterLock( ) release the specific locks. Calling ReleaseReaderLock( ) on a writer lock releases both the writer lock and the reader lock. However, calling ReleaseWriterLock( ) on a reader lock throws a System.ApplicationException.

ReleaseLock( ) causes any lock to be released, but it returns a LockCookie, which represents the type of lock that RestoreLock can use to obtain the same lock. UpgradeToWriterLock( ) upgrades a reader lock to a writer lock, and returns a LockCookie representing the original reader lock. Pass that cookie to DowngradeDromWriterLock( ) to restore the original reader lock.

public sealed class ReaderWriterLock {
// Public Constructors
   public ReaderWriterLock( );
// Public Instance Properties
   public bool IsReaderLockHeld{get; }
   public bool IsWriterLockHeld{get; }
   public int WriterSeqNum{get; }
// Public Instance Methods
   public void AcquireReaderLock(int millisecondsTimeout);
   public void AcquireReaderLock(TimeSpan timeout);
   public void AcquireWriterLock(int millisecondsTimeout);
   public void AcquireWriterLock(TimeSpan timeout);
   public bool AnyWritersSince(int seqNum);
   public void DowngradeFromWriterLock(ref LockCookie lockCookie);
   public LockCookie ReleaseLock( );
   public void ReleaseReaderLock( );
   public void ReleaseWriterLock( ); public void ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Joe Mayo

Publisher Resources

ISBN: 0596005261Catalog PageErrata