HDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mutex_pool< Mutex, Key, Hash, Bins > Class Template Reference

#include <thread.h>

Public Member Functions

 mutex_pool () noexcept
 
Mutexoperator[] (const Key &key) noexcept
 

Detailed Description

template<class Mutex, class Key, class Hash, size_t Bins = 16>
class mutex_pool< Mutex, Key, Hash, Bins >

Mutex pool. Sometimes, we have lots of objects that need to be individually locked for thread safety, but two separate objects don't need to lock against each other. If there are many more objects than threads, it's wasteful for each object to contain its own mutex. So a solution is to make a mutex_pool – a collection of several mutexes. Each object uses a hash to choose a consistent mutex for itself, but which will be unlikely to be locked simultaneously by different object. Semantically, it looks rather like an associative array of mutexes. We also ensure that the mutexes are all on different cache lines, to ensure that they don't exhibit false sharing. Try to choose Bins larger than the expected number of threads that will be simultaneously locking mutexes.

Definition at line 525 of file thread.h.

Constructor & Destructor Documentation

template<class Mutex , class Key , class Hash , size_t Bins = 16>
mutex_pool< Mutex, Key, Hash, Bins >::mutex_pool ( )
inlinenoexcept

Definition at line 527 of file thread.h.

Member Function Documentation

template<class Mutex , class Key , class Hash , size_t Bins = 16>
Mutex& mutex_pool< Mutex, Key, Hash, Bins >::operator[] ( const Key &  key)
inlinenoexcept

Definition at line 528 of file thread.h.


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