Pthread Functions

The pthread_mutex_init() routine creates a single mutual exclusion lock (mutex). EWL will always pass NULL as the second attr argument, which means to use default mutex attributes. Return zero upon success, return an error code upon failure.

The pthread_mutex_destroy() routine disposes of a single mutex. Return zero upon success, return an error code upon failure.

The pthread_mutex_lock() routine acquires a lock on a single mutex. If the mutex is already locked when pthread_mutex_lock() is called, the routine blocks execution of the current thread until the mutex is available. Return zero upon success, return an error code upon failure.

The pthread_mutex_unlock() routine releases a lock on a single mutex. Return zero upon success, return an error code upon failure.

Additionally, when EWL_LOCALDATA_AVAILABLE is on, four more pthread routines in the pthread_platform.c file are used by EWL to implement thread local data:

The following macros, listed in table below are used to configure and use the EWL threading support:
Table 1. EWL Thread Management Macros
Macro Behavior
EWL_THREADSAFE Defined to 0 if there is no multithread support in EWL. Defined to 1 if there should be multithread support in EWL. When defined to 1, many internal aspects of EWL are guarded by critical regions. Having critical regions inside EWL will slow down the execution time for the tradeoff of working correctly on a multithreaded system. Also, many EWL functions will use thread local storage for maintaining state information.
EWL_PTHREADS Defined to 1 if the EWL platform supportsthe POSIX threading model. Defined to 0 if the EWL platform does not support the POSIX threading model. It is an error to define EWL_PTHREADS to 1 and EWL_THREADSAFE to 0. EWL has generic support for the POSIX thread model, so turning on EWL_THREADSAFE and EWL_THREADS is enough to properly support a multithreaded system without the need to write any additional support code.
EWL_LOCALDATA Internal EWL flag for accessing thread local data when EWL_THREADSAFE is 1. Accesses static global data when EWL_THREADSAFEis 0.
EWL_LOCALDATA_AVAILABLE Defined to 1 if the EWL platform supports thread local data, accessible using the EWL_LOCALDATA macro. Defined to 0 if the EWL platform does not support thread local data.