TBarrier and TMutexPool

Hi everyone,

Some time ago I’ve written two helper classes to improve the usage of threads in ROOT: a barrier and a mutex pool. Maybe they come in handy for you too.

To explain what the classes do, I’ll just quote my own documentation here:

// The TBarrier class provides a synchronization mechanism for
// a group of TThreads.
// A barrier is initialized with the number of threads that have
// to run into the barrier in order to tear the barrier down and
// continue processing. This mechanism is typically used if a
// stepwise task should be processed by a number of threads in
// parallel and where the threads have to synchronize in between
// the single steps.

// The TMutexPool class provides a means to map a huge number of resources
// that needs mutex protection onto a fixed and usually small number of
// mutexes.
// The main idea of a mutex pool is to provide a fixed number of mutexes
// and distribute them based on a simple indexing scheme. The mutex pool
// overloads the [] operator such that a mutex of the pool can be accessed
// via an index. The index can be any number. It does NOT have to be smaller
// than the number of mutexes in the pool. Internally, each index is used
// modulo the number of mutexes to access a certain mutex. Thus, the only
// requirement is, that the index used to address a mutex is constant to
// that usage, i.e., each resource should have a constant id, e.g., provided
// by TObject::Hash();

I’ve used these classes in Root-5, but they should work also under Root-6. :wink:

TBarrier.cpp (3.14 KB)
TBarrier.h (786 Bytes)
TMutexPool.cpp (1.75 KB)
TMutexPool.h (560 Bytes)