Loading...
Searching...
No Matches
threads.h File Reference

Platform-independent multithreading support. More...

#include <stdio.h>
#include "visibility.h"
#include "atomic.h"

Classes

struct  PLMD::thread_mpi::tMPI_Thread_barrier_t
 Pthread implementation of barrier type. More...
 
struct  PLMD::thread_mpi::tMPI_Thread_cond_t
 Condition variable handle for threads. More...
 
struct  PLMD::thread_mpi::tMPI_Thread_key_t
 Pthread implementation of the abstract tMPI_Thread_key type. More...
 
struct  PLMD::thread_mpi::tMPI_Thread_mutex_t
 Opaque mutex datatype. More...
 
struct  PLMD::thread_mpi::tMPI_Thread_once_t
 One-time initialization data for thread. More...
 

Namespaces

namespace  PLMD
 Fast (possibly busy-wait-based) barrier type.
 
namespace  PLMD::thread_mpi
 

Macros

#define TMPI_FARGS   __FILE__, __LINE__
 Convenience macro for the first two arguments to tMPI_Fatal_error().
 
#define TMPI_THREAD_BARRIER_INITIALIZER(count)
 Static initializer for tMPI_Thread_barrier_t.
 
#define TMPI_THREAD_COND_INITIALIZER   { {0}, NULL}
 Static initializer for tMPI_Thread_cond_t.
 
#define TMPI_THREAD_MUTEX_INITIALIZER   { {0}, NULL }
 Static initializer for tMPI_Thread_mutex_t.
 
#define TMPI_THREAD_ONCE_INIT   { {0} }
 Static initializer for tMPI_Thread_once_t.
 

Typedefs

typedef struct tMPI_Thread * PLMD::thread_mpi::tMPI_Thread_t
 

Functions

TMPI_EXPORT void PLMD::thread_mpi::tMPI_Fatal_error (const char *file, int line, const char *message,...)
 handle a fatal error.
 
Mutexes
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_mutex_destroy (tMPI_Thread_mutex_t *mtx)
 Kill a mutex you no longer need.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_mutex_init (tMPI_Thread_mutex_t *mtx)
 Initialize a new mutex.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_mutex_lock (tMPI_Thread_mutex_t *mtx)
 Wait for exclusive access to a mutex.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_mutex_trylock (tMPI_Thread_mutex_t *mtx)
 Try to lock a mutex, return if busy.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_mutex_unlock (tMPI_Thread_mutex_t *mtx)
 Release the exclusive access to a mutex.
 
Thread-specific storage
TMPI_EXPORT void * PLMD::thread_mpi::tMPI_Thread_getspecific (tMPI_Thread_key_t key)
 Get value for thread-specific-storage in this thread.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_key_create (tMPI_Thread_key_t *key, void(*destructor)(void *))
 Initialize thread-specific-storage handle.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_key_delete (tMPI_Thread_key_t key)
 Delete thread-specific-storage handle.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_setspecific (tMPI_Thread_key_t key, void *value)
 Set value for thread-specific-storage in this thread.
 
Run-once
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_once (tMPI_Thread_once_t *once_data, void(*init_routine)(void))
 Run the provided routine exactly once.
 
Condition variables
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cond_broadcast (tMPI_Thread_cond_t *cond)
 Unblock all waiting threads.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cond_destroy (tMPI_Thread_cond_t *cond)
 Destroy condition variable.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cond_init (tMPI_Thread_cond_t *cond)
 Initialize condition variable.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cond_signal (tMPI_Thread_cond_t *cond)
 Unblock one waiting thread.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cond_wait (tMPI_Thread_cond_t *cond, tMPI_Thread_mutex_t *mtx)
 Wait for a condition to be signaled.
 
Barriers
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_barrier_destroy (tMPI_Thread_barrier_t *barrier)
 Release data in a barrier datatype.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_barrier_init (tMPI_Thread_barrier_t *barrier, int count)
 Initialize a synchronization barrier type.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_barrier_wait (tMPI_Thread_barrier_t *barrier)
 Perform barrier synchronization.
 

Thread creation, destruction, and inspection

TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_cancel (tMPI_Thread_t thread)
 Ask a thread to exit.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_create (tMPI_Thread_t *thread, void *(*start_routine)(void *), void *arg)
 Create a new thread.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_equal (tMPI_Thread_t t1, tMPI_Thread_t t2)
 Check whether two thread pointers point to the same thread.
 
TMPI_EXPORT void PLMD::thread_mpi::tMPI_Thread_exit (void *value_ptr)
 Terminate calling thread.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_get_hw_number (void)
 Get the number of hardware threads that can be run simultaneously.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_join (tMPI_Thread_t thread, void **value_ptr)
 Wait for a specific thread to finish executing.
 
TMPI_EXPORT tMPI_Thread_t PLMD::thread_mpi::tMPI_Thread_self (void)
 Get a thread ID of the calling thread.
 
TMPI_EXPORT int PLMD::thread_mpi::tMPI_Thread_setaffinity_single (tMPI_Thread_t thread, unsigned int nr)
 Set thread affinity to a single core.
 
enum  PLMD::thread_mpi::tMPI_Thread_setaffinity_support { PLMD::thread_mpi::TMPI_SETAFFINITY_SUPPORT_NO = 0 , PLMD::thread_mpi::TMPI_SETAFFINITY_SUPPORT_YES = 1 }
 Thread setaffinity support status enumeration. More...
 
enum  PLMD::thread_mpi::tMPI_Thread_support { PLMD::thread_mpi::TMPI_THREAD_SUPPORT_NO = 0 , PLMD::thread_mpi::TMPI_THREAD_SUPPORT_YES = 1 }
 Thread support status enumeration. More...
 

Detailed Description

Platform-independent multithreading support.

This file provides an portable thread interface very similar to POSIX threads, as a thin wrapper around the threads provided operating system (whether they be POSIX threads or something else).

In other words, while the naming conventions are very similar to pthreads, you should NOT assume that a thread_mpi thread type (thread,mutex,key, etc) is the same as the Pthreads equivalent, even on platforms where we are using pthreads.

Because the synchronization functions here are similar to the basic mutexes/conditions/barriers provided by the operating system, performance will most likely be worse than when using the atomic synchronization functions of atomic.h. On the other hand, because the operating system can schedule out waiting threads using these functions, they are the appropriate ones for I/O and initialization.

Since this module is merely intended to be a transparent wrapper around a system-dependent thread implementation, we simply echo errors to stderr. The user should check the return codes] and take appropriate action when using these functions (fat chance, but errors are rare).

Macro Definition Documentation

◆ TMPI_FARGS

#define TMPI_FARGS   __FILE__, __LINE__

Convenience macro for the first two arguments to tMPI_Fatal_error().

◆ TMPI_THREAD_BARRIER_INITIALIZER

#define TMPI_THREAD_BARRIER_INITIALIZER ( count)
Value:
{ \
NULL, count, count, 0 \
}

Static initializer for tMPI_Thread_barrier_t.

See the description of the tMPI_Thread_barrier_t datatype for instructions on how to use this. Note that variables initialized with this value MUST have static storage allocation.

Parameters
countThreshold for barrier

◆ TMPI_THREAD_COND_INITIALIZER

#define TMPI_THREAD_COND_INITIALIZER   { {0}, NULL}

Static initializer for tMPI_Thread_cond_t.

See the description of the tMPI_Thread_cond_t datatype for instructions on how to use this. Note that any variables initialized with this value MUST have static storage allocation.

◆ TMPI_THREAD_MUTEX_INITIALIZER

#define TMPI_THREAD_MUTEX_INITIALIZER   { {0}, NULL }

Static initializer for tMPI_Thread_mutex_t.

See the description of the tMPI_Thread_mutex_t datatype for instructions on how to use this. Note that any variables initialized with this value MUST have static storage allocation.

◆ TMPI_THREAD_ONCE_INIT

#define TMPI_THREAD_ONCE_INIT   { {0} }

Static initializer for tMPI_Thread_once_t.

See the description of the tMPI_Thread_once_t datatype for instructions on how to use this. Normally, all variables of that type should be initialized statically to this value.