core.sync.rwmutex

The read/write mutex module provides a primitive for maintaining shared read access and mutually exclusive write access.

Types 1

This class represents a mutex that allows any number of readers to enter, but when a writer enters, all other readers and writers are blocked.

Please note that this mutex is not recursive and is intended to guard access to data only. Also, no deadlock checking is in place because doing so would require dynamic memory allocation, which would reduce performance by an unacceptable amount. As a result, any attempt to recursively acquire this mutex may well deadlock the caller, particularly if a write lock is acquired while holding a read lock, or vice-versa. In practice, this should not be an issue however, because it is uncommon to call deeply into unknown code while holding a lock that simply protects data.

Fields
Policy m_policy
Reader m_reader
Writer m_writer
Mutex m_commonMutex
Condition m_readerQueue
Condition m_writerQueue
int m_numQueuedReaders
int m_numActiveReaders
int m_numQueuedWriters
int m_numActiveWriters
Methods
Policy policy() @property @safe nothrowGets the policy used by this mutex.
Policy policy() @property shared @safe nothrowditto
Reader reader() @property @safe nothrowGets an object representing the reader lock for the associated mutex.
shared(Reader) reader() @property shared @safe nothrowditto
Writer writer() @property @safe nothrowGets an object representing the writer lock for the associated mutex.
shared(Writer) writer() @property shared @safe nothrowditto
Constructors
this( Policy policy = Policy.PREFER_WRITERS )Initializes a read/write mutex object with the supplied policy.
this( Policy policy = Policy.PREFER_WRITERS )ditto
Nested Templates
PolicyDefines the policy used by this mutex. Currently, two policies are defined.
ReaderThis class can be considered a mutex in its own right, and is used to negotiate a read lock for the enclosing mutex.
WriterThis class can be considered a mutex in its own right, and is used to negotiate a write lock for the enclosing mutex.