GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Typedefs | Functions
thpool.h File Reference

Types and functions for the thread pool. More...

#include <pthread.h>
#include <semaphore.h>
#include <hwloc.h>
#include "error.h"
Include dependency graph for thpool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ghost_thpool
 The thread pool consisting of all shepherd threads that will ever handle a GHOST task. More...
 

Typedefs

typedef struct ghost_thpool ghost_thpool
 The thread pool consisting of all shepherd threads that will ever handle a GHOST task. More...
 

Functions

ghost_error ghost_thpool_create (int nThreads, void *(*func)(void *))
 Creates or resizes a thread pool. More...
 
ghost_error ghost_thpool_destroy ()
 Destroy the thread pool. More...
 
ghost_error ghost_thpool_get (ghost_thpool **thpool)
 Get the thread pool. More...
 
ghost_error ghost_thpool_key (pthread_key_t *key)
 
ghost_error ghost_thpoolhread_add (void *(func)(void *), intptr_t arg)
 

Detailed Description

Types and functions for the thread pool.

@{

Author
Moritz Kreutzer morit.nosp@m.z.kr.nosp@m.eutze.nosp@m.r@fa.nosp@m.u.de

Typedef Documentation

typedef struct ghost_thpool ghost_thpool

The thread pool consisting of all shepherd threads that will ever handle a GHOST task.

Function Documentation

ghost_error ghost_thpool_create ( int  nThreads,
void *(*)(void *)  func 
)

Creates or resizes a thread pool.

Parameters
nThreadsThe number of threads in the thread pool.
funcThe start routine for each thread.
Returns
GHOST_SUCCESS on success or an error indicator.

In GHOST, the start routine works on a task queue. In a usual scenario one would like to have one shepherd thread for each processing unit. This assures that N tasks can run at the same time if each one occupies on processing unit. If this function is called a second, third etc. time, the size of the thread pool will be resized to the given nThreads.

ghost_error ghost_thpool_destroy ( )

Destroy the thread pool.

Returns
GHOST_SUCCESS on success or an error indicator.

Before free'ing the resources, all pthreads in the thread pool are being joined (this is also where an error could occur).

ghost_error ghost_thpool_get ( ghost_thpool **  thpool)

Get the thread pool.

Parameters
thpoolWhere to store the thread pool.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_thpool_key ( pthread_key_t *  key)
ghost_error ghost_thpoolhread_add ( void *  func)(void *,
intptr_t  arg 
)