mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.5000.0 2.0.0.0 4.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.Runtime.ConstrainedExecution.CriticalFinalizerObject System.Runtime.InteropServices.ComVisible(true)

The dnprdnshort has two reader-writer locks, and . is recommended for all new development. is similar to , but it has simplified rules for recursion and for upgrading and downgrading lock state. avoids many cases of potential deadlock. In addition, the performance of is significantly better than .

is used to synchronize access to a resource. At any given time, it allows either concurrent read access for multiple threads, or write access for a single thread. In a situation where a resource is changed infrequently, a ReaderWriterLock provides better throughput than a simple one-at-a-time lock, such as .

ReaderWriterLock works best where most accesses are reads, while writes are infrequent and of short duration. Multiple readers alternate with single writers, so that neither readers nor writers are blocked for long periods.

Holding reader locks or writer locks for long periods will starve other threads. For best performance, consider restructuring your application to minimize the duration of writes.

A thread can hold a reader lock or a writer lock, but not both at the same time. Instead of releasing a reader lock in order to acquire the writer lock, you can use and .

Recursive lock requests increase the lock count on a lock.

Readers and writers are queued separately. When a thread releases the writer lock, all threads waiting in the reader queue at that instant are granted reader locks; when all of those reader locks have been released, the next thread waiting in the writer queue, if any, is granted the writer lock, and so on. In other words, ReaderWriterLock alternates between a collection of readers, and one writer.

While a thread in the writer queue is waiting for active reader locks to be released, threads requesting new reader locks accumulate in the reader queue. Their requests are not granted, even though they could share concurrent access with existing reader-lock holders; this helps protect writers against indefinite blockage by readers.

Most methods for acquiring locks on a ReaderWriterLock accept time-out values. Use time-outs to avoid deadlocks in your application. For example, a thread might acquire the writer lock on one resource and then request a reader lock on a second resource; in the meantime, another thread might acquire the writer lock on the second resource, and request a reader lock on the first. Unless time-outs are used, the threads deadlock.

If the time-out interval expires and the lock request has not been granted, the method returns control to the calling thread by throwing an . A thread can catch this exception and determine what action to take next.

Time-outs are expressed in milliseconds. If you use a to specify the time-out, the value used is the total number of whole milliseconds represented by the . The following table shows the valid time-out values in milliseconds.

Value

Description

-1

The thread waits until the lock is acquired, regardless of how long it takes. For methods that specify integer time-outs, the constant can be used.

0

The thread does not wait to acquire the lock. If the lock cannot be acquired immediately, the method returns.

>0

The number of milliseconds to wait.

With the exception of -1, negative time-out values are not allowed. If you specify a negative integer other than -1, a time-out value of zero is used instead. (That is, the method returns without waiting, if the lock cannot be acquired immediately.) If you specify a that represents a negative number of milliseconds other than -1, is thrown.

Defines a lock that supports single writers and multiple readers.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  To be added

  Initializes a new instance of the class.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  blocks if a different thread has the writer lock, or if at least one thread is waiting for the writer lock.

  If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on the writer lock is incremented. This prevents a thread from blocking on its own writer lock. The result is exactly the same as calling , and an additional call to is required when releasing the writer lock.

  AcquireReaderLock supports recursive reader-lock requests. That is, a thread can call AcquireReaderLock multiple times, which increments the lock count each time. You must call once for each time you call AcquireReaderLock. Alternatively, you can call to reduce the lock count to zero immediately.

  Recursive lock requests are always granted immediately, without placing the requesting thread in the reader queue. Use recursive locks with caution, to avoid blocking writer-lock requests for long periods.

  For valid time-out values, see .

  Acquires a reader lock, using an value for the time-out.

  The time-out in milliseconds.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  blocks if a different thread has the writer lock, or if at least one thread is waiting for the writer lock.

  If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on the writer lock is incremented. This prevents a thread from blocking on its own writer lock. The result is exactly the same as calling , and an additional call to is required when releasing the writer lock.

  AcquireReaderLock supports recursive reader-lock requests. That is, a thread can call AcquireReaderLock multiple times, which increments the lock count each time. You must call once for each time you call AcquireReaderLock. Alternatively, you can call to reduce the lock count to zero immediately.

  Recursive lock requests are always granted immediately, without placing the requesting thread in the reader queue. Use recursive locks with caution, to avoid blocking writer-lock requests for long periods.

  For valid time-out values, see .

  Acquires a reader lock, using a value for the time-out.

  A TimeSpan specifying the time-out period.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method blocks if another thread has a reader lock or writer lock. For a description of the way the writer lock alternates with multiple concurrent reader locks, see the class.

  A thread that already has a reader lock can acquire the writer lock in one of two ways: by releasing the reader lock before calling , or by calling .

  If a thread calls AcquireWriterLock while it still has a reader lock, it will block on its own reader lock; if an infinite time-out is specified, the thread will deadlock. To avoid such deadlocks, use to determine whether the current thread already has a reader lock.

  AcquireWriterLock supports recursive writer-lock requests. That is, a thread can call AcquireWriterLock multiple times, which increments the lock count each time. You must call once for each time you call AcquireWriterLock. Alternatively, you can call to reduce the lock count to zero immediately.

  Recursive lock requests are always granted immediately, without placing the requesting thread in the writer queue.

  For valid time-out values, see .

  Acquires the writer lock, using an value for the time-out.

  The time-out in milliseconds.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method blocks if another thread has a reader lock or writer lock. For a description of the way the writer lock alternates with multiple concurrent reader locks, see the class.

  A thread that already has a reader lock can acquire the writer lock in one of two ways: by releasing the reader lock before calling , or by calling .

  If a thread calls AcquireWriterLock while it still has a reader lock, it will block on its own reader lock; if an infinite time-out is specified, the thread will deadlock. To avoid such deadlocks, use to determine whether the current thread already has a reader lock.

  AcquireWriterLock supports recursive writer-lock requests. That is, a thread can call AcquireWriterLock multiple times, which increments the lock count each time. You must call once for each time you call AcquireWriterLock. Alternatively, you can call to reduce the lock count to zero immediately.

  Recursive lock requests are always granted immediately, without placing the requesting thread in the writer queue.

  For valid time-out values, see .

  Acquires the writer lock, using a value for the time-out.

  The TimeSpan specifying the time-out period.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  You can use and AnyWritersSince to improve application performance. For example, a thread might cache the information it obtains while holding a reader lock. After releasing and later reacquiring the lock, the thread can use AnyWritersSince to determine whether other threads have written to the resource in the interim; if not, the cached information can be used. This technique is useful where reading the information protected by the lock is expensive; for example, running a database query.

  The caller must be holding a reader lock or a writer lock in order for the sequence number to be useful.

  Indicates whether the writer lock has been granted to any thread since the sequence number was obtained.

  true if the writer lock has been granted to any thread since the sequence number was obtained; otherwise, false.

  The sequence number.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` To be added: an object of type 'LockCookie&' To be added To be added
- Method
  2.0.0.0
  4.0.0.0
  System.Void To be added. To be added.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  get: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Boolean To be added: an object of type 'bool' To be added

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

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  get: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Boolean To be added: an object of type 'bool' To be added

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

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.LockCookie

  releases the reader lock or writer lock, regardless of the recursive lock count. To restore the state of the lock, including the lock count, pass the to .

  Releases the lock, regardless of the number of times the thread acquired the lock.

  A value representing the released lock.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  decrements the lock count. When the count reaches zero, the lock is released.

  If a thread has the writer lock, calling ReleaseReaderLock has the same effect as calling . If a thread has no locks, calling ReleaseReaderLock throws an .

  Decrements the lock count.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  decrements the writer lock count. When the count reaches zero, the writer lock is released.

  If a thread has a reader lock, or no locks, calling ReleaseWriterLock throws an .

  Decrements the lock count on the writer lock.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` To be added: an object of type 'LockCookie&' To be added To be added
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.LockCookie ``

  When a thread calls UpgradeToWriterLock the reader lock is released, regardless of the lock count, and the thread goes to the end of the queue for the writer lock. Thus, other threads might write to the resource before the thread that requested the upgrade is granted the writer lock.

  The time-out exception is not thrown until the thread that called the method can reacquire the reader lock. If there are no other threads waiting for the writer lock, this happens immediately. However, if another thread is queued for the writer lock, the thread that called the method cannot reacquire the reader lock until all current readers have released their locks, and one thread has acquired and released the writer lock. This is true even if the other thread that requested the writer lock requested it after the current thread called the method.

  To restore the lock state, call using the returned by UpgradeToWriterLock. Do not use this LockCookie with .

  When a thread has no reader lock, do not use UpgradeToWriterLock. Use instead.

  For valid time-out values, see .

  Upgrades a reader lock to the writer lock, using an Int32 value for the time-out.

  A value.

  The time-out in milliseconds.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.LockCookie ``

  When a thread calls UpgradeToWriterLock the reader lock is released, regardless of the lock count, and the thread goes to the end of the queue for the writer lock. Thus, other threads might write to the resource before the thread that requested the upgrade is granted the writer lock.

  The time-out exception is not thrown until the thread that called the method can reacquire the reader lock. If there are no other threads waiting for the writer lock, this happens immediately. However, if another thread is queued for the writer lock, the thread that called the method cannot reacquire the reader lock until all current readers have released their locks, and one thread has acquired and released the writer lock. This is true even if the other thread that requested the writer lock requested it after the current thread called the method.

  To restore the lock state, call using the returned by UpgradeToWriterLock. Do not use this LockCookie with .

  When a thread has no reader lock, do not use UpgradeToWriterLock. Use instead.

  For valid time-out values, see .

  Upgrades a reader lock to the writer lock, using a TimeSpan value for the time-out.

  A value.

  The TimeSpan specifying the time-out period.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 To be added: an object of type 'int'

  The sequence number increases whenever a thread acquires the writer lock. You can save the sequence number and pass it to at a later time, if you want to determine whether other threads have acquired the writer lock in the meantime.

  You can use WriterSeqNum to improve application performance. For example, a thread might cache the information it obtains while holding a reader lock. After releasing and later reacquiring the lock, the thread can determine whether other threads have written to the resource by calling AnyWritersSince; if not, the cached information can be used. This technique is useful when reading the information protected by the lock is expensive; for example, running a database query.

  The caller must be holding a reader lock or a writer lock in order for the sequence number to be useful.

  Gets the current sequence number.