Xmipp
v3.23.11-Nereus
|
#include <xmipp_threads.h>
Public Member Functions | |
void | setData (void *data, int nThread=-1) |
ThreadManager (int numberOfThreads, void *workClass=NULL) | |
~ThreadManager () | |
void | run (ThreadFunction function, void *data=NULL) |
void | runAsync (ThreadFunction function, void *data=NULL) |
void | wait () |
int | getNumberOfThreads () |
Public Attributes | |
int | threads |
number of working threads. More... | |
Friends | |
void * | _threadMain (void *data) |
Class for manage a group of threads performing one or several tasks. This class is very useful when we have some function that can be executed in parallel by threads. The threads are created in the contructor of the object and released in destructor. This way threads can execute different functions at diffent moments and exit at the end of manager life. Also, the wait() function allow in the main thread to wait until all threads have finish working on a task and maybe then execute another one. This class is supposed to be used only in the main thread.
Definition at line 239 of file xmipp_threads.h.
ThreadManager::ThreadManager | ( | int | numberOfThreads, |
void * | workClass = NULL |
||
) |
Constructor, number of working threads should be supplied
Definition at line 205 of file xmipp_threads.cpp.
ThreadManager::~ThreadManager | ( | ) |
|
inline |
void ThreadManager::run | ( | ThreadFunction | function, |
void * | data = NULL |
||
) |
Function to start working in a task. The function that you want to execute in parallel by the working threads should be passed as argument. If data is passed, then it is set to all threads. Functions that can be executed by thread should by of the type ThreadFunction, i.e., return void * and only one argument of type ThreadArgument. The call of this function will block the main thread until all workers finish their job, if you don't want to block use runAsync instead, and later can call wait for waiting until threads are done.
Definition at line 264 of file xmipp_threads.cpp.
void ThreadManager::runAsync | ( | ThreadFunction | function, |
void * | data = NULL |
||
) |
void ThreadManager::setData | ( | void * | data, |
int | nThread = -1 |
||
) |
Set data for working threads. If nThread = -1 then data is set for all threads.
Definition at line 216 of file xmipp_threads.cpp.
void ThreadManager::wait | ( | ) |
Function that should be called to wait until all threads finished work
Definition at line 282 of file xmipp_threads.cpp.
|
friend |
function to start running the threads. Should be external and declared as friend
This function is used in ThreadManager as the main threads function to live in.
Definition at line 173 of file xmipp_threads.cpp.
int ThreadManager::threads |
number of working threads.
Definition at line 242 of file xmipp_threads.h.