tbb::interface5::reader_writer_lock Class Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Friends | List of all members
tbb::interface5::reader_writer_lock Class Reference
Synchronization

Writer-preference reader-writer lock with local-only spinning on readers. More...

`#include <reader_writer_lock.h>`

Inheritance diagram for tbb::interface5::reader_writer_lock:

## Classes
class | scoped_lock
| The scoped lock pattern for write locks. More...
class | scoped_lock_read
| The scoped lock pattern for read locks. More...

## Public Types
enum | status_t { waiting_nonblocking, waiting, active, invalid }
| Status type for nodes associated with lock instances. More...

## Public Member Functions
| reader_writer_lock ()
| Constructs a new reader_writer_lock.
| ~reader_writer_lock ()
| Destructs a reader_writer_lock object.
void __TBB_EXPORTED_METHOD | lock ()
| Acquires the reader_writer_lock for write. More...
bool __TBB_EXPORTED_METHOD | try_lock ()
| Tries to acquire the reader_writer_lock for write. More...
void __TBB_EXPORTED_METHOD | lock_read ()
| Acquires the reader_writer_lock for read. More...
bool __TBB_EXPORTED_METHOD | try_lock_read ()
| Tries to acquire the reader_writer_lock for read. More...
void __TBB_EXPORTED_METHOD | unlock ()
| Releases the reader_writer_lock.

## Friends
class | scoped_lock
class | scoped_lock_read

## Detailed Description

Writer-preference reader-writer lock with local-only spinning on readers.

Loosely adapted from Mellor-Crummey and Scott pseudocode at http://www.cs.rochester.edu/research/synchronization/pseudocode/rw.html#s_wp

## Member Enumeration Documentation

enum tbb::interface5::reader_writer_lock::status_t

Status type for nodes associated with lock instances.

waiting_nonblocking: the wait state for nonblocking lock instances; for writes, these transition straight to active states; for reads, these are unused.

waiting: the start and spin state for all lock instances; these will transition to active state when appropriate. Non-blocking write locks transition from this state to waiting_nonblocking immediately.

active: the active state means that the lock instance holds the lock; it will transition to invalid state during node deletion

invalid: the end state for all nodes; this is set in the destructor so if we encounter this state, we are looking at memory that has already been freed

The state diagrams below describe the status transitions. Single arrows indicate that the thread that owns the node is responsible for the transition; double arrows indicate that any thread could make the transition.

State diagram for scoped_lock status:

waiting -------—> waiting_nonblocking | _____________/ | V V V active --------------—> invalid

State diagram for scoped_lock_read status:

waiting | V active --------------—>invalid

## Member Function Documentation

void __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::lock | ( | ) |  |

Acquires the reader_writer_lock for write.

If the lock is currently held in write mode by another context, the writer will block by spinning on a local variable. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.

void __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::lock_read | ( | ) |  |

Acquires the reader_writer_lock for read.

If the lock is currently held by a writer, this reader will block and wait until the writers are done. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.

bool __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::try_lock | ( | ) |  |

Tries to acquire the reader_writer_lock for write.

This function does not block. Return Value: True or false, depending on whether the lock is acquired or not. If the lock is already held by this acquiring context, try_lock() returns false.

bool __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::try_lock_read | ( | ) |  |

Tries to acquire the reader_writer_lock for read.

This function does not block. Return Value: True or false, depending on whether the lock is acquired or not.

The documentation for this class was generated from the following file:

- reader_writer_lock.h

Copyright © 2005-2015 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.