Xmipp  v3.23.11-Nereus
Classes | Functions
Collaboration diagram for Threads:

Classes

class  Mutex
 
class  Condition
 
class  Barrier
 
class  Thread
 
class  ThreadManager
 
class  ThreadArgument
 
class  ParallelTaskDistributor
 
class  ThreadTaskDistributor
 
struct  mybarrier_t
 

Functions

void * _singleThreadMain (void *data)
 
void * _threadMain (void *data)
 

Old parallel stuff.

typedef struct mybarrier_t barrier_t
 
int barrier_init (barrier_t *barrier, int needed)
 
int barrier_destroy (barrier_t *barrier)
 
int barrier_wait (barrier_t *barrier)
 

Detailed Description

Typedef Documentation

◆ barrier_t

typedef struct mybarrier_t barrier_t

Barrier structure

Function Documentation

◆ _singleThreadMain()

void* _singleThreadMain ( void *  data)

This function is used from the Thread class to provide a wrapper over pthreads. This will be the real function called from pthread_create and from this the function thread.run() will be called.

Definition at line 146 of file xmipp_threads.cpp.

146  {
147  Thread * thread = (Thread*) data;
148  thread->run();
149  return NULL;
150 }
virtual void run()=0

◆ _threadMain()

void* _threadMain ( void *  data)

This function is used in ThreadManager as the main threads function to live in.

function to start running the threads. Should be external and declared as friend

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

◆ barrier_destroy()

int barrier_destroy ( barrier_t barrier)

Barrier destruction

Definition at line 375 of file xmipp_threads.cpp.

376 {
377  pthread_mutex_destroy(&barrier->mutex);
378  pthread_cond_destroy(&barrier->cond);
379  return 0;
380 }
pthread_cond_t cond
Condition on which the threads are waiting.
pthread_mutex_t mutex
Mutex to update this structure.

◆ barrier_init()

int barrier_init ( barrier_t barrier,
int  needed 
)

Barrier initialization

Definition at line 366 of file xmipp_threads.cpp.

367 {
368  barrier->needed = needed;
369  barrier->called = 0;
370  pthread_mutex_init(&barrier->mutex, NULL);
371  pthread_cond_init(&barrier->cond, NULL);
372  return 0;
373 }
int called
How many threads already arrived.
int needed
How many threads should be awaited.
pthread_cond_t cond
Condition on which the threads are waiting.
pthread_mutex_t mutex
Mutex to update this structure.

◆ barrier_wait()

int barrier_wait ( barrier_t barrier)

Wait at the barrier

Definition at line 382 of file xmipp_threads.cpp.

383 {
384  pthread_mutex_lock(&barrier->mutex);
385  barrier->called++;
386  if (barrier->called == barrier->needed)
387  {
388  barrier->called = 0;
389  pthread_cond_broadcast(&barrier->cond);
390  }
391  else
392  {
393  pthread_cond_wait(&barrier->cond,&barrier->mutex);
394  }
395  pthread_mutex_unlock(&barrier->mutex);
396  return 0;
397 }
int called
How many threads already arrived.
int needed
How many threads should be awaited.
pthread_cond_t cond
Condition on which the threads are waiting.
pthread_mutex_t mutex
Mutex to update this structure.