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.