Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Friends | List of all members
ThreadArgument Class Reference

#include <xmipp_threads.h>

Public Member Functions

 ThreadArgument ()
 
 ThreadArgument (int id, ThreadManager *manager=NULL, void *data=NULL)
 
int getNumberOfThreads ()
 

Public Attributes

int thread_id
 The thread id. More...
 
int threads
 Number of threads. More...
 
void * workClass
 The class in which threads will be working. More...
 
void * data
 

Friends

class ThreadManager
 
void * _threadMain (void *data)
 

Detailed Description

Class to pass arguments to threads functions. The argument passed can be obtained casting the void * data received in the function.

See also
ThreadManager

Definition at line 337 of file xmipp_threads.h.

Constructor & Destructor Documentation

◆ ThreadArgument() [1/2]

ThreadArgument::ThreadArgument ( )

Definition at line 154 of file xmipp_threads.cpp.

155 {
156  thread_id = -1;
157  threads = -1;
158  manager = NULL;
159  data = NULL;
160  workClass = NULL;
161 }
int threads
Number of threads.
void * workClass
The class in which threads will be working.
int thread_id
The thread id.

◆ ThreadArgument() [2/2]

ThreadArgument::ThreadArgument ( int  id,
ThreadManager manager = NULL,
void *  data = NULL 
)

Definition at line 163 of file xmipp_threads.cpp.

164 {
165  this->thread_id = id;
166  this->threads = manager->threads;
167  this->manager = manager;
168  this->data = data;
169  this->workClass = NULL;
170 }
int threads
number of working threads.
int threads
Number of threads.
void * workClass
The class in which threads will be working.
int thread_id
The thread id.

Member Function Documentation

◆ getNumberOfThreads()

int ThreadArgument::getNumberOfThreads ( )
inline

Definition at line 352 of file xmipp_threads.h.

352 {return manager->getNumberOfThreads();}
int getNumberOfThreads()

Friends And Related Function Documentation

◆ _threadMain

void* _threadMain ( void *  data)
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.

174 {
175  ThreadArgument * thArg = (ThreadArgument*) data;
176  ThreadManager * thMgr = thArg->manager;
177 
178  while (true)
179  {
180  //Wait for start working or leave
181  thMgr->wait();
182  //After awaked check what to do
183  if (thMgr->workFunction != NULL)
184  {
185  try
186  {
187  thMgr->workFunction(*thArg);
188  thMgr->wait(); //wait for finish together
189  }
190  catch (XmippError &xe)
191  {
192  std::cerr << xe.what() << std::endl
193  << "In thread " << thArg->thread_id << std::endl;
194 // pthread_exit(NULL);
195  exit(xe.__errno);
196  }
197  }
198  else //exit thread
199  {
200  pthread_exit(NULL);
201  }
202  }
203 }
ThreadManager * thMgr
int thread_id
The thread id.
ErrorType __errno
Definition: xmipp_error.h:227

◆ ThreadManager

friend class ThreadManager
friend

Definition at line 350 of file xmipp_threads.h.

Member Data Documentation

◆ data

void* ThreadArgument::data

Definition at line 345 of file xmipp_threads.h.

◆ thread_id

int ThreadArgument::thread_id

The thread id.

Definition at line 342 of file xmipp_threads.h.

◆ threads

int ThreadArgument::threads

Number of threads.

Definition at line 343 of file xmipp_threads.h.

◆ workClass

void* ThreadArgument::workClass

The class in which threads will be working.

Definition at line 344 of file xmipp_threads.h.


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