ReaderWriterMutex Concept

The ReaderWriterMutex Concept extends the Mutex Concept to include the notion of reader-writer locks. It introduces a Boolean parameter, write, that specifies whether a writer lock (write = true) or reader lock (write = false) is being requested. Multiple reader locks can be held simultaneously on a ReaderWriterMutex if it does not have a writer lock on it. A writer lock on a ReaderWriterMutex excludes all other tasks from holding a lock on the mutex at the same time.

Table 7-3 shows the requirements for ReaderWriterMutexRW.

Table 7-3. ReaderWriterMutex Concept

Pseudosignature

Semantics

RW ()

Construct an unlocked mutex.

~RW ()

Destroy an unlocked mutex.

RW ::scoped_lock::acquire(RW&, bool write=true)

Acquire lock on mutex.

RW ::scoped_lock::release( )

Release lock.

bool RW::scoped_lock::upgrade_to_writer( )

Change reader lock to writer lock.

bool RW::scoped_lock::downgrade_to_reader( )

Change writer lock to reader lock.

Get Intel Threading Building Blocks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.