Skip to main content

Posix Threads (pthread)

Functions

pthread_attr_getdetachstate(const pthread_attr_t attr, int detachstate)#

int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • int * detachstate: the destination for the detach state

Details#

This function gets the detach state from attr and stores it in detachstate.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)#

int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • int detachstate: the new detach state (PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE)

Details#

This function sets the detach state in attr with detachstate.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object
  • EINVAL: detachstate is not a valid

pthread_attr_getguardsize(const pthread_attr_t attr, size_t guardsize)#

int pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *guardsize)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • size_t * guardsize: the destination for the new guard size

Details#

This function gets the guard size from attr and stores it in guardsize.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)#

int pthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize)

Type: int

Parameters:

  • pthread_attr_t * attr
  • size_t guardsize

Details#

This function is not supported. The guard size is a fixed value that cannot be set by the user.

Returns:

-1 with errno (see Errno) set to ENOTSUP

pthread_attr_getinheritsched(const pthread_attr_t attr, int inheritsched)#

int pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inheritsched)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • int * inheritsched: the destination for the inherit sched value

Details#

This function gets the inherit sched value from attr and stores it in inheritsched.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)#

int pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • int inheritsched: the new inherit sched value

Details#

This function sets the inherit sched in attr with inheritsched.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object
  • EINVAL: inheritsched is not a valid value

pthread_attr_getschedparam(const pthread_attr_t attr, struct sched_param param)#

int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • struct sched_param * param: the destination for the sched param value

Details#

This function gets the scheduling parameters from attr and stores it in param.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setschedparam(pthread_attr_t attr, const struct sched_param param)#

int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • const struct sched_param * param: the source for the sched param value

Details#

This function sets the scheduling parameters in attr with param.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_getschedpolicy(const pthread_attr_t attr, int policy)#

int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • int * policy: the destination for the schedule policy value

Details#

This function gets the scheduling policy from attr and stores it in policy.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)#

int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • int policy: the new policy value (SCHED_FIFO, SCHED_RR, or SCHED_OTHER)

Details#

This function sets the scheduling policy in attr with policy.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object
  • EINVAL: policy does not refer to a valid policy.

pthread_attr_getscope(const pthread_attr_t attr, int contentionscope)#

int pthread_attr_getscope (const pthread_attr_t *attr, int *contentionscope)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • int * contentionscope: the destination for the contention scope value

Details#

This function gets the contention scope from attr and stores it in contentionscope.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)#

int pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • int contentionscope: the new contention scope value

Details#

This function sets the contention scope in attr with contentionscope.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object
  • ENOTSUP: contentionscope is not PTHREAD_SCOPE_SYSTEM or PTHREAD_SCOPE_PROCESS

pthread_attr_getstacksize(const pthread_attr_t attr, size_t stacksize)#

int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • size_t * stacksize: the destination for the new stack size

Details#

This functions gets the stack size from attr and stores it in stacksize.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)#

int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure
  • size_t stacksize: the new stack size value

Details#

This function sets the stack size in attr with stacksize.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object
  • EINVAL: stacksize is too low of a value
  • ENOMEM: not enough memory

pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)#

int pthread_attr_getstackaddr (const pthread_attr_t *attr, void **stackaddr)

Type: int

Parameters:

  • const pthread_attr_t * attr: a pointer to the attributes structure
  • void ** stackaddr: the destination for the stack address

Details#

This functions gets the stack address from attr and stores it in stackaddr.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr does not refer to an initialized thread attribute object

pthread_attr_setstackaddr(pthread_attr_t attr, void stackaddr)#

int pthread_attr_setstackaddr (pthread_attr_t *attr, void *stackaddr)

Type: int

Parameters:

  • pthread_attr_t * attr
  • void * stackaddr

Details#

This function is not supported.

Returns:

-1 with errno equal to ENOTSUP

pthread_attr_init(pthread_attr_t *attr)#

int pthread_attr_init (pthread_attr_t *attr)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure

Details#

This function initializes attr to the default values.

Returns:

0 on success

pthread_attr_destroy(pthread_attr_t *attr)#

int pthread_attr_destroy (pthread_attr_t *attr)

Type: int

Parameters:

  • pthread_attr_t * attr: a pointer to the attributes structure

Details#

Destroys the pthead attributes. This function frees the stack associated with the thread. The attributes should not be destroyed until the thread is done executing.

Returns:

0 on success or -1 and errno set to:

  • EINVAL: attr is NULL or uninitialized

pthread_cancel(pthread_t thread)#

int pthread_cancel (pthread_t thread)

Type: int

Parameters:

  • pthread_t thread

Details#

This function cancels the specified thread.

Returns:

Zero on success or -1 with errno set.

pthread_setcancelstate(int state, int *oldstate)#

int pthread_setcancelstate (int state, int *oldstate)

Type: int

Parameters:

  • int state
  • int * oldstate

Details#

sets the cancel state of the calling thread.

Returns:

-1 with errno equal to ENOTSUP

pthread_setcanceltype(int type, int *oldtype)#

int pthread_setcanceltype (int type, int *oldtype)

Type: int

Parameters:

  • int type
  • int * oldtype

Details#

Sets the cancel type of the calling thread.

Returns:

Zero on success or -1 with errno set to:

  • ENOTSUP: type is PTHREAD_CANCEL_ASYNCHRONOUS which is not supported
  • EINVAL: type is not PTHREAD_CANCEL_DEFERRED which is not supported

pthread_testcancel()#

void pthread_testcancel ()

Type: void

pthread_cond_init(pthread_cond_t cond, const pthread_condattr_t attr)#

int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr)

Type: int

Parameters:

  • pthread_cond_t * cond
  • const pthread_condattr_t * attr

Details#

This function initializes a pthread block condition.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond or attr is NULL

pthread_cond_destroy(pthread_cond_t *cond)#

int pthread_cond_destroy (pthread_cond_t *cond)

Type: int

Parameters:

  • pthread_cond_t * cond

Details#

This function destroys a pthread block condition.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond is NULL

pthread_cond_broadcast(pthread_cond_t *cond)#

int pthread_cond_broadcast (pthread_cond_t *cond)

Type: int

Parameters:

  • pthread_cond_t * cond

Details#

This function wakes all threads that are blocked on cond.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond is NULL or not initialized

pthread_cond_signal(pthread_cond_t *cond)#

int pthread_cond_signal (pthread_cond_t *cond)

Type: int

Parameters:

  • pthread_cond_t * cond

Details#

This function wakes the highest priority thread that is blocked on cond.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond is NULL or not initialized

pthread_cond_wait(pthread_cond_t cond, pthread_mutex_t mutex)#

int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)

Type: int

Parameters:

  • pthread_cond_t * cond
  • pthread_mutex_t * mutex

Details#

This function causes the calling thread to block on cond. When called, mutex must be locked by the caller.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond is NULL or not initialized
  • EACCES: cond is from a different process and not shared
  • EPERM: the caller does not have a lock on mutex

pthread_cond_timedwait(pthread_cond_t cond, pthread_mutex_t mutex, const struct timespec *abstime)#

int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)

Type: int

Parameters:

  • pthread_cond_t * cond
  • pthread_mutex_t * mutex
  • const struct timespec * abstime

Details#

This function causes the calling thread to block on cond. When called, mutex must be locked by the caller. If cond does not wake the process by abstime, the thread resumes.Example:

struct timespec abstime;clock_gettime(CLOCK_REALTIME, &abstime);abstime.tv_sec += 5; //time out after five secondsif ( pthread_cond_timedwait(cond, mutex, &abstime) == -1 ){     if ( errno == ETIMEDOUT ){          //Timedout     } else {          //Failed     }}

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: cond is NULL or not initialized
  • EACCES: cond is from a different process and not shared
  • EPERM: the caller does not have a lock on mutex
  • ETIMEDOUT: abstime passed before cond arrived

pthread_condattr_init(pthread_condattr_t *attr)#

int pthread_condattr_init (pthread_condattr_t *attr)

Type: int

Parameters:

  • pthread_condattr_t * attr

Details#

This function initializes attr with the default values.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is NULL

pthread_condattr_destroy(pthread_condattr_t *attr)#

int pthread_condattr_destroy (pthread_condattr_t *attr)

Type: int

Parameters:

  • pthread_condattr_t * attr

Details#

This function destroys attr.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is not an initialized condition attribute

pthread_condattr_getpshared(const pthread_condattr_t attr, int pshared)#

int pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared)

Type: int

Parameters:

  • const pthread_condattr_t * attr
  • int * pshared

Details#

This function gets the pshared value for attr and stores it in pshared.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is not an initialized condition attribute

pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)#

int pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared)

Type: int

Parameters:

  • pthread_condattr_t * attr
  • int pshared

Details#

This function sets the pshared value in attr to pshared.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is not an initialized condition attribute
  • EINVAL: pshared is not PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE

pthread_condattr_getclock(const pthread_condattr_t attr, clockid_t clock_id)#

int pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id)

Type: int

Parameters:

  • const pthread_condattr_t * attr
  • clockid_t * clock_id

Details#

This function gets the clock associated with pthread_cond_timedwait() operations.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is not an initialized condition attribute

pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)#

int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id)

Type: int

Parameters:

  • pthread_condattr_t * attr
  • clockid_t clock_id

Details#

pthread_cond_timedwait() operations always use CLOCK_REALTIME. This value cannot be changed.

Returns:

-1 with errno set to:

  • ENOTSUP: this function is not supported

pthread_create(pthread_t thread, const pthread_attr_t attr, void (start_routine)(void ), void arg)#

int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)

Type: int

Parameters:

  • pthread_t * thread: If not null, the thread id is written here
  • const pthread_attr_t * attr: Sets the thread attributes (defaults are used if this is NULL)
  • void *(*)(void *) start_routine: A pointer to the start routine
  • void * arg: A pointer to the start routine's single argument

Details#

This function creates a new thread.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • ENOMEM: error allocating memory for the thread
  • EAGAIN: insufficient system resources to create a new thread

pthread_join(pthread_t thread, void **value_ptr)#

int pthread_join (pthread_t thread, void **value_ptr)

Type: int

Parameters:

  • pthread_t thread
  • void ** value_ptr

Details#

This function blocks the calling thread until thread terminates.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • ESRCH: thread does not exist
  • EDEADLK: a deadlock has been detected or thread refers to the calling thread
  • EINVAL: thread does not refer to a joinable thread.

pthread_exit(void *value_ptr)#

void pthread_exit (void *value_ptr)

Type: void

Parameters:

  • void * value_ptr

pthread_mutex_lock(pthread_mutex_t *mutex)#

int pthread_mutex_lock (pthread_mutex_t *mutex)

Type: int

Parameters:

  • pthread_mutex_t * mutex

Details#

This function locks mutex. If mutex cannot be locked immediately, the thread is blocked until mutex is available.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: mutex is NULL
  • EDEADLK: the caller already holds the mutex
  • ETIMEDOUT: abstime passed before cond arrived

pthread_mutex_trylock(pthread_mutex_t *mutex)#

int pthread_mutex_trylock (pthread_mutex_t *mutex)

Type: int

Parameters:

  • pthread_mutex_t * mutex

Details#

This function tries to lock mutex. If mutex cannot be locked immediately, the function returns without the lock.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: mutex is NULL
  • EBUSY: mutex is locked by another thread

pthread_mutex_unlock(pthread_mutex_t *mutex)#

int pthread_mutex_unlock (pthread_mutex_t *mutex)

Type: int

Parameters:

  • pthread_mutex_t * mutex

Details#

This function unlocks mutex.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: mutex is NULL
  • EACCES: the caller does not have a lock on mutex

pthread_mutex_destroy(pthread_mutex_t *mutex)#

int pthread_mutex_destroy (pthread_mutex_t *mutex)

Type: int

Parameters:

  • pthread_mutex_t * mutex

Details#

This function destroys mutex.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: mutex is NULL

pthread_mutex_timedlock(pthread_mutex_t mutex, const struct timespec abs_timeout)#

int pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abs_timeout)

Type: int

Parameters:

  • pthread_mutex_t * mutex
  • const struct timespec * abs_timeout

Details#

This function causes the calling thread to lock mutex. It mutex cannot be locked, the thread is block until either the mutex is locked or abs_timeout is greater than CLOCK_REALTIME.Example:

struct timespec abstime;clock_gettime(CLOCK_REALTIME, &abstime);abstime.tv_sec += 5; //time out after five secondsif ( pthread_mutex_timedlock(mutex, &abstime) == -1 ){     if ( errno == ETIMEDOUT ){          //Timedout     } else {          //Failed     }}

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: mutex or abs_timeout is NULL
  • EDEADLK: the caller already holds the mutex
  • ETIMEDOUT: abstime passed before cond arrived

pthread_mutex_getprioceiling(pthread_mutex_t mutex, int prioceiling)#

int pthread_mutex_getprioceiling (pthread_mutex_t *mutex, int *prioceiling)

Type: int

Parameters:

  • pthread_mutex_t * mutex
  • int * prioceiling

Details#

This function gets the mutex priority ceiling from mutex and stores it in prioceiling.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: mutex or prioceiling is NULL

pthread_mutex_setprioceiling(pthread_mutex_t mutex, int prioceiling, int old_ceiling)#

int pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling, int *old_ceiling)

Type: int

Parameters:

  • pthread_mutex_t * mutex
  • int prioceiling
  • int * old_ceiling

Details#

This function sets mutex priority ceiling to prioceiling. If old_ceiling is not NULL, the old ceiling value is stored there.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: mutex is NULL

pthread_mutex_init(pthread_mutex_t mutex, const pthread_mutexattr_t attr) MCU_WEAK#

int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) MCU_WEAK

Type: int

Parameters:

  • pthread_mutex_t * mutex
  • const pthread_mutexattr_t * attr

Details#

This function initializes mutex with attr.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: mutex is NULL

pthread_mutexattr_getprioceiling(const pthread_mutexattr_t attr, int prioceiling)#

int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr, int *prioceiling)

Type: int

Parameters:

  • const pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int * prioceiling: Destination pointer (cannot be NULL)

Details#

This function gets the priority ceiling from attr and stores it in prioceiling.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prio_ceiling)#

int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr, int prio_ceiling)

Type: int

Parameters:

  • pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int prio_ceiling: The priority ceiling to set

Details#

This function sets the priority ceiling in attr to prio_ceiling.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_getprotocol(const pthread_mutexattr_t attr, int protocol)#

int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)

Type: int

Parameters:

  • const pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int * protocol: Pointer to the destination protocol

Details#

This function gets the protocol from attr and stores it in protocol.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)#

int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol)

Type: int

Parameters:

  • pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int protocol: The new protocol

Details#

This function sets protocol in attr to protocol.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_getpshared(const pthread_mutexattr_t attr, int pshared)#

int pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr, int *pshared)

Type: int

Parameters:

  • const pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int * pshared: The pointer to the destination pshared value

Details#

This function gets the process shared value from attr and stores it in pshared.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)#

int pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared)

Type: int

Parameters:

  • pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int pshared: The new pshared value (non-zero to share with other processes)

Details#

This function sets the process shared value in attr to pshared. A non-zero pshared means the mutex is shared.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object
  • EINVAL: pshared is not PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE

pthread_mutexattr_gettype(const pthread_mutexattr_t attr, int type)#

int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)

Type: int

Parameters:

  • const pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int * type: The destination pointer for the type

Details#

This function gets the type from attr and stores it in type.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)#

int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)

Type: int

Parameters:

  • pthread_mutexattr_t * attr: Mutex Thread Attribute Object
  • int type: The new type either PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_RECURSIVE

Details#

This function sets the type in attr to type. The type value should be on of:

  • PTHREAD_MUTEX_NORMAL
  • PTHREAD_MUTEX_RECURSIVE

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • EINVAL: attr does not refer to an initialized mutex attribute object

pthread_mutexattr_init(pthread_mutexattr_t *attr)#

int pthread_mutexattr_init (pthread_mutexattr_t *attr)

Type: int

Parameters:

  • pthread_mutexattr_t * attr

Details#

This function initializes attr with default values.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is NULL

pthread_mutexattr_destroy(pthread_mutexattr_t *attr)#

int pthread_mutexattr_destroy (pthread_mutexattr_t *attr)

Type: int

Parameters:

  • pthread_mutexattr_t * attr

Details#

This function destroys attr.

Returns:

Zero on success or -1 with errno set to:

  • EINVAL: attr is not an initialized mutex attribute object

pthread_getschedparam(pthread_t thread, int policy, struct sched_param param)#

int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)

Type: int

Parameters:

  • pthread_t thread
  • int * policy
  • struct sched_param * param

Details#

This function gets thread's scheduling policy and scheduling parameters and stores them in policy and param respectively.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • ESRCH: thread is not a valid
  • EINVAL: policy or param is NULL

pthread_setschedparam(pthread_t thread, int policy, struct sched_param *param)#

int pthread_setschedparam (pthread_t thread, int policy, struct sched_param *param)

Type: int

Parameters:

  • pthread_t thread
  • int policy
  • struct sched_param * param

Details#

This function sets thread's scheduling policy and scheduling parameters to policy and param respectively.

Returns:

Zero on success or -1 with errno (see Errno) set to:

  • ESRCH: thread is not a valid
  • EINVAL: param is NULL or the priority is invalid

pthread_self()#

pthread_t pthread_self ()

Type: pthread_t

Details#

This function returns the thread ID of the calling process.

Returns:

The thread ID of the caller.