Member classes const_accessor and accessor are called accessors. Accessors allow multiple threads to concurrently access pairs in a shared concurrent_hash_map. An accessor acts as a smart pointer to a pair in a concurrent_hash_map. It holds an implicit lock on a pair until the instance is destroyed or method release is called on the accessor.
Classes const_accessor and accessor differ in the kind of access that they permit.
Class |
value_type |
Implied Lock on pair |
---|---|---|
const_accessor |
const std::pair<const Key,T> |
Reader lock – permits shared access with other readers. |
accessor |
std::pair<const Key,T> |
Writer lock – permits exclusive access by a thread. Blocks access by other threads. |
Accessors cannot be assigned or copy-constructed, because allowing such would greatly complicate the locking semantics.
Summary
Provides read-only access to a pair in a concurrent_hash_map.
template<typename Key, typename T, typename HashCompare, typename A> class concurrent_hash_map<Key,T,HashCompare,A>::const_accessor;
#include "tbb/concurrent_hash_map.h"
A const_accessor permits read-only access to a key-value pair in a concurrent_hash_map.
namespace tbb { template<typename Key, typename T, typename HashCompare, typename A> class concurrent_hash_map<Key,T,HashCompare,A>::const_accessor { public: // types typedef const std::pair<const Key,T> value_type; // construction and destruction const_accessor(); ~const_accessor(); // inspection bool empty() const; const value_type& operator*() const; const value_type* operator->() const; // early release void release(); }; }
Member | Description |
---|---|
bool empty() const |
Returns: True if instance points to nothing; false if instance points to a key-value pair. |
void release() |
If !empty(), releases the implied lock on the pair, and sets instance to point to nothing. Otherwise does nothing. |
const value_type& operator*() const |
Raises assertion failure if empty() and TBB_USE_ASSERT is defined as nonzero. Returns: Const reference to key-value pair. |
const value_type* operator->() const |
Returns: &operator*() |
const_accessor() |
Constructs const_accessor that points to nothing. |
~const_accessor |
If pointing to key-value pair, releases the implied lock on the pair. |
Summary
Class that provides read and write access to a pair in a concurrent_hash_map.
template<typename Key, typename T, typename HashCompare, typename Alloc> class concurrent_hash_map<Key,T,HashCompare,A>::accessor;
#include "tbb/concurrent_hash_map.h"
An accessor permits read and write access to a key-value pair in a concurrent_hash_map. It is derived from a const_accessor, and thus can be implicitly cast to a const_accessor.
namespace tbb { template<typename Key, typename T, typename HashCompare, typename Alloc> class concurrent_hash_map<Key,T,HashCompare,Alloc>::accessor: concurrent_hash_map<Key,T,HashCompare,Alloc>::const_accessor { public: typedef std::pair<const Key,T> value_type; value_type& operator*() const; value_type* operator->() const; }; }
Member | Description |
---|---|
value_type& operator*() const |
Raises assertion failure if empty() and TBB_USE_ASSERT is defined as non-zero. Returns: Reference to key-value pair. |
value_type* operator->() const |
Returns: &operator*() |