#include <pthread.h> #include <sched.h>
CRTCMOD library/module DEFINE(_MULTI_THREADED) OR #define _MULTI_THREADED
| type | Description |
|---|---|
| pthread_attr_t | Thread creation attribute |
| pthread_cleanup_entry_np_t | Cancelation cleanup handler entry |
| pthread_condattr_t | Condition variable creation attribute |
| pthread_cond_t | Condition Variable synchronization primitive |
| pthread_joinoption_np_t | Options structure for extensions to pthread_join() |
| pthread_key_t | Thread local storage key |
| pthread_mutexattr_t | Mutex creation attribute |
| pthread_mutex_t | Mutex (Mutual exclusion) synchronization primitive |
| pthread_once_t | Once time initialization control variable |
| pthread_option_np_t | Pthread run-time options structure |
| pthread_rwlockattr_t | Read/Write lock attribute |
| pthread_rwlock_t | Read/Write synchronization primitive |
| pthread_t | Pthread handle |
| pthread_id_np_t | Thread ID. For use as an integral type. |
| struct sched_param | Scheduling parameters (priority and policy) |
After creating the primitive objects of type pthread_cond_t and pthread_mutex_t using the appropriate initialization functions, those objects must not be copied or moved to a new location. If the condition variable or mutex is copied or moved to a new location, the new primitive object will be invalid and unable to be used. Attempts to use the new object will result in the EINVAL error.
Function prototypes
All functions except for pthread_exit(), pthread_getspecific(), pthread_self(), pthread_test_exit_np(), pthread_is_multithreaded_np()and pthread_getconcurrency() return an errno value to indicate failure, or 0 to indicate success.
| Attribute | Default value | supported values |
|---|---|---|
| detachstate | PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_DETACHED |
| schedparam | SCHED_OTHER with priority equal to PRIORITY_DEFAULT (0) | SCHED_OTHER with priority <= PTHREAD_PRIO_MAX and priority >= PTHREAD_PRIO_MIN |
| contentionscope | PTHREAD_SCOPE_SYSTEM | PTHREAD_SCOPE_SYSTEM |
| inheritsched | PTHREAD_EXPLICIT_SCHED, priority equal PRIORITY_DEFAULT (0) | PTHREAD_EXPLICIT_SCHED or PTHREAD_INHERIT_SCHED |
| schedpolicy | SCHED_OTHER | SCHED_OTHER |
int pthread_attr_destroy(pthread_attr_t *attr);
int pthread_attr_getdetachstate(const pthread_attr_t *attr,
int *detachstate);
int pthread_attr_getinheritsched(pthread_attr_t *attr,
int *inheritsched);
int pthread_attr_getschedparam(const pthread_attr_t *attr,
struct sched_param *param);
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_setdetachstate(pthread_attr_t *attr,
int detachstate);
int pthread_attr_setinheritsched(pthread_attr_t *attr,
int inheritsched);
int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *param);
int pthread_clear_exit_np(void);
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int pthread_delay_np(const struct timespec *interval);
int pthread_detach(pthread_t thread);
int pthread_equal(pthread_t thread1, pthread_t thread2);
void pthread_exit(void *status);
int pthread_extendedjoin_np(pthread_t thread, void **status,
pthread_joinoption_np_t *options);
int pthread_getconcurrency(void);
void pthread_getpthreadoption_np(pthread_option_np_t *option);
int pthread_getschedparam(pthread_t thread, int *policy,
struct sched_param *param);
pthread_id_np_t pthread_getthreadid_np(void);
int pthread_getunique_np(pthread_t thread, pthread_id_np_t *id);
int pthread_is_multithreaded_np(pthread_t thread, void **status);
int pthread_join(pthread_t thread, void **status);
int pthread_join_np(pthread_t thread, void **status);
int pthread_once(pthread_once_t *once_control,
void (*init_routine)(void));
pthread_t pthread_self(void);
int pthread_setconcurrency(void);
void pthread_setpthreadoption_np(pthread_option_np_t *option);
int pthread_setschedparam(pthread_t thread, int policy,
const struct sched_param *param);
int sched_yield(void);
| Cancel State | Cancel Type | Cancelation Action |
|---|---|---|
| PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_ASYNCHRONOUS | Cancel the thread immediately and asynchronously |
| PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED | defer cancelation until a cancelation point is encountered |
| PTHREAD_CANCEL_DISABLE | PTHREAD_CANCEL_ASYNCHRONOUS | defer cancelation until the cancel state changed to enabled |
| PTHREAD_CANCEL_DISABLE | PTHREAD_CANCEL_DEFERRED | defer cancelation until the cancel state changed to enabled |
The default thread cancelation action is `defer cancelation until a cancelation point'. i.e. cancel state equal to PTHREAD_CANCEL_ENABLE, cancel type equal to PTHREAD_CANCEL_DEFERRED.
The following functions are cancelation points: pthread_join(), pthread_join_np(), pthread_testcancel(), pthread_cond_wait(), pthread_cond_timedwait(), pthread_delay_np().
int pthread_cancel(pthread_t thread);
void pthread_cleanup_peek_np(pthread_cleanup_entry_np_t *top);
void pthread_cleanup_pop(int execute);
void pthread_cleanup_push(void (*routine)(void *), void *arg);
int pthread_getcancelstate_np(int *cancelState);
int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype(int type, int *oldtype);
void pthread_testcancel(void);
int pthread_test_exit_np(void **status);
void *pthread_getspecific(pthread_key_t key);
int pthread_key_create(pthread_key_t *key,
void (*destructor)(void *));
int pthread_key_delete(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);
| Attribute | Default value | supported values |
|---|---|---|
| pshared | PTHREAD_PROCESS_PRIVATE | PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED |
| kind (non portable) | PTHREAD_MUTEX_NONRECURSIVE_NP | PTHREAD_MUTEX_NONRECURSIVE_NP or PTHREAD_MUTEX_RECURSIVE_NP |
| name (non portable) | PTHREAD_DEFAULT_MUTEX_NAME_NP "QP0WMTX UNNAMED" | Any name 15 characters or less. If not terminated by a null character, name is truncated to 15 characters. |
| type | PTHREAD_MUTEX_DEFAULT (PTHREAD_MUTEX_NORMAL) | PTHREAD_MUTEX_DEFAULT or PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_OWNERTERM_NP The PTHREAD_MUTEX_OWNERTERM_NP attribute value is non portable |
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
int pthread_mutexattr_getkind_np(const pthread_mutexattr_t *attr,
int *kind);
int pthread_mutexattr_getname_np(const pthread_mutexattr_t *attr,
char *name);
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
int *pshared);
int pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type);
int pthread_mutexattr_init(pthread_mutexattr_t *attr);
int pthread_mutexattr_setkind_np(const pthread_mutexattr_t *attr,
int kind);
int pthread_mutexattr_setname_np(pthread_mutexattr_t *attr,
const char *name);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_set_mutexattr_default_np(int kind);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr); OR
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_timedlock_np(pthread_mutex_t *mutex,
const struct timespec *deltatime);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_lock_global_np(void);
int pthread_unlock_global_np(void);
| Attribute | Default value | supported values |
|---|---|---|
| pshared | PTHREAD_PROCESS_PRIVATE | PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED |
int pthread_condattr_destroy(pthread_condattr_t *attr);
int pthread_condattr_init(pthread_condattr_t *attr);
int pthread_condattr_getpshared(const pthread_condattr_t *attr,
int *pshared);
int pthread_condattr_setpshared(const pthread_condattr_t *attr,
int pshared);
int pthread_cond_broadcast(pthread_cond_t *cond);
int pthread_cond_destroy(pthread_cond_t *cond);
int pthread_cond_init(pthread_cond_t *cond,
const pthread_condattr_t *attr); OR
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex,
const struct timespec *abstime);
int pthread_cond_wait(pthread_cond_t *cond,
pthread_mutex_t *mutex);
int pthread_get_expiration_np(const struct timespec *delta,
struct timespec *abstime);
| Attribute | Default value | supported values |
|---|---|---|
| pshared | PTHREAD_PROCESS_PRIVATE | PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED |
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
int pthread_rwlockatttr_getpshared(const pthread_rwlockattr_t *attr,
int *pshared);
int pthread_rwlockatttr_setpshared(pthread_rwlockattr_t *attr,
int pshared);
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_init(pthread_rwlock_t *rwlock,
const pthread_rwlockattr_t *attr); OR
pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_timedrdlock_np(pthread_rwlock_t *rwlock,
const struct timespec *deltatime);
int pthread_rwlock_timedwrlock_np(pthread_rwlock_t *rwlock,
const struct timespec *deltatime);
int pthread_rwlock_tryrdlock_np(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock_np(pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_kill(pthread_t thread, int sig)
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
int pthread_signal_to_cancel_np(sigset_t *set, pthread_t *thread);
int pthread_atfork(void (*prepare)(void),
void (*parent)(void),
void (*child)(void));
int pthread_atfork_np(int *userstate,
void (*prepare)(void),
void (*parent)(void),
void (*child)(void));
int pthread_attr_getguardsize(const pthread_attr_t *attr,
size_t *guardsize);
int pthread_attr_getschedpolicy(pthread_attr_t *attr,
int *policy);
int pthread_attr_getscope(pthread_attr_t *attr,
int *contentionscope);
int pthread_attr_getstackaddr(const pthread_attr_t *attr,
void **stackaddr);
int pthread_attr_getstacksize(const pthread_attr_t *attr,
size_t *stacksize);
int pthread_attr_setguardsize(pthread_attr_t *attr,
size_t guardsize);
int pthread_attr_setschedpolicy(pthread_attr_t *attr,
int policy);
int pthread_attr_setscope(pthread_attr_t *attr,
int contentionscope);
int pthread_attr_setstackaddr(pthread_attr_t *attr,
void *stackaddr);
int pthread_attr_setstacksize(pthread_attr_t *attr,
size_t stacksize);
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr,
int *prioceiling);
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
int *protocol);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
int prioceiling);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
int protocol);
int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
int *prioceiling);
int pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
int prioceiling, int *oldceiling);
| Constant | Description |
|---|---|
| _POSIX_THREADS | Base threads |
| _POSIX_THREAD_ATTR_STACKADDR | Stack address attribute. Not present in the OS/400 implementation. |
| _POSIX_THREAD_ATTR_STACKSIZE | Stack size attribute. Not present in the OS/400 implementation. |
| _POSIX_THREAD_PRIORITY_SCHEDULING | Thread priority scheduling. Not present in the OS/400 implementation. |
| _POSIX_THREAD_PRIO_INHERIT | Mutex priority inheritance. Not present in the OS/400 implementation. |
| _POSIX_THREAD_PRIO_PROTECT | Mutex priority ceiling. Not present in the OS/400 implementation. |
| _POSIX_THREAD_PROCESS_SHARED | Synchronization primitives may be shared between processes. |