Xmipp
v3.23.11-Nereus
|
#include <xmipp_threads.h>
Public Member Functions | |
Barrier (int numberOfThreads) | |
~Barrier () | |
void | wait () |
Class to synchronize several threads in some point of execution. Threads is a way of distributing workload across different workers to solve a problem faster. Nevertheless, sometimes we need synchronization between threads to avoid undesired race conditions and other problems. Here we are an implementation of a barrier that allows putting all threads to wait at a given point until all of them have reached such point and can continue working. Barriers are usually available through pthreads system library. Nonetheless, sometimes it is not so we have to implement it here.
Definition at line 150 of file xmipp_threads.h.
Barrier::Barrier | ( | int | numberOfThreads | ) |
Constructor of the barrier to initialize the object. You should pass the number of working threads that you want to wait on the barrier. The internal counter of the barrier will be initialized with numberOfThreads + 1 taking into account the main thread, so it need to wait also in the barrier with the worker threads to all can move on.
Definition at line 97 of file xmipp_threads.cpp.
Barrier::~Barrier | ( | ) |
Destructor to free all memory used
Definition at line 104 of file xmipp_threads.cpp.
void Barrier::wait | ( | ) |
Request to wait in this meet point. For each thread calling this function the execution will be paused until all threads arrive this point.
Definition at line 109 of file xmipp_threads.cpp.