Zephyr Project API  3.3.0
A Scalable Open Source RTOS
pthread.h File Reference
#include <zephyr/kernel.h>
#include <zephyr/wait_q.h>
#include <zephyr/posix/time.h>
#include <zephyr/posix/unistd.h>
#include "posix_types.h"
#include <zephyr/posix/sched.h>
#include "pthread_key.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define PTHREAD_CREATE_DETACHED   0
 
#define PTHREAD_CREATE_JOINABLE   1
 
#define PTHREAD_CANCEL_ENABLE   (0U << _PTHREAD_CANCEL_POS)
 
#define PTHREAD_CANCEL_DISABLE   BIT(_PTHREAD_CANCEL_POS)
 
#define PTHREAD_ONCE_INIT
 
#define PTHREAD_STACK_MIN   Z_KERNEL_STACK_SIZE_ADJUST(0)
 
#define PTHREAD_COND_INITIALIZER   (-1)
 Declare a condition variable as initialized. More...
 
#define PTHREAD_COND_DEFINE(name)   pthread_cond_t name = PTHREAD_COND_INITIALIZER
 Declare a pthread condition variable. More...
 
#define PTHREAD_MUTEX_INITIALIZER   (-1)
 Declare a mutex as initialized. More...
 
#define PTHREAD_MUTEX_DEFINE(name)   pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
 Declare a pthread mutex. More...
 
#define PTHREAD_MUTEX_NORMAL   0
 
#define PTHREAD_MUTEX_RECURSIVE   1
 
#define PTHREAD_MUTEX_ERRORCHECK   2
 
#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL
 
#define PTHREAD_PRIO_NONE   0
 
#define PTHREAD_BARRIER_DEFINE(name, count)
 Declare a pthread barrier. More...
 
#define PTHREAD_BARRIER_SERIAL_THREAD   1
 

Functions

int pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
int pthread_cond_destroy (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_signal (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_broadcast (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_wait (pthread_cond_t *cv, pthread_mutex_t *mut)
 POSIX threading compatibility API. More...
 
int pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mut, const struct timespec *abstime)
 POSIX threading compatibility API. More...
 
static int pthread_condattr_init (pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
static int pthread_condattr_destroy (pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
int pthread_mutex_destroy (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_lock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_unlock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_timedlock (pthread_mutex_t *m, const struct timespec *abstime)
 POSIX threading compatibility API. More...
 
int pthread_mutex_trylock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_init (pthread_mutex_t *m, const pthread_mutexattr_t *att)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
 POSIX threading compatibility API. More...
 
static int pthread_mutexattr_init (pthread_mutexattr_t *m)
 POSIX threading compatibility API. More...
 
static int pthread_mutexattr_destroy (pthread_mutexattr_t *m)
 POSIX threading compatibility API. More...
 
int pthread_barrier_wait (pthread_barrier_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrier_init (pthread_barrier_t *b, const pthread_barrierattr_t *attr, unsigned int count)
 POSIX threading compatibility API. More...
 
static int pthread_barrier_destroy (pthread_barrier_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrierattr_init (pthread_barrierattr_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrierattr_destroy (pthread_barrierattr_t *b)
 POSIX threading compatibility API. More...
 
pthread_t pthread_self (void)
 Obtain ID of the calling thread. More...
 
static int pthread_equal (pthread_t pt1, pthread_t pt2)
 Compare thread IDs. More...
 
static int pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr)
 Destroy the read-write lock attributes object. More...
 
static int pthread_rwlockattr_init (pthread_rwlockattr_t *attr)
 initialize the read-write lock attributes object. More...
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 
int pthread_attr_init (pthread_attr_t *attr)
 
int pthread_attr_destroy (pthread_attr_t *attr)
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *schedparam)
 
int pthread_getschedparam (pthread_t pthread, int *policy, struct sched_param *param)
 
int pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
 
int pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize)
 
int pthread_once (pthread_once_t *once, void(*initFunc)(void))
 
void pthread_exit (void *retval)
 
int pthread_join (pthread_t thread, void **status)
 
int pthread_cancel (pthread_t pthread)
 
int pthread_detach (pthread_t thread)
 
int pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*threadroutine)(void *), void *arg)
 
int pthread_setcancelstate (int state, int *oldstate)
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *schedparam)
 
int pthread_setschedparam (pthread_t pthread, int policy, const struct sched_param *param)
 
int pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
 
int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime)
 
int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime)
 
int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
 
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)
 
void * pthread_getspecific (pthread_key_t key)
 
int pthread_setname_np (pthread_t thread, const char *name)
 Set name of POSIX thread. More...
 
int pthread_getname_np (pthread_t thread, char *name, size_t len)
 Get name of POSIX thread and store in name buffer that is of size len. More...
 

Macro Definition Documentation

◆ PTHREAD_BARRIER_DEFINE

#define PTHREAD_BARRIER_DEFINE (   name,
  count 
)
Value:
struct pthread_barrier name = { \
.wait_q = Z_WAIT_Q_INIT(&name.wait_q), \
.max = count, \
}
ZTEST_BMEM int count
Definition: main.c:33

Declare a pthread barrier.

Declaration API for a pthread barrier. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the barrier
countThread count, same as the "count" argument to pthread_barrier_init()

◆ PTHREAD_BARRIER_SERIAL_THREAD

#define PTHREAD_BARRIER_SERIAL_THREAD   1

◆ PTHREAD_CANCEL_DISABLE

#define PTHREAD_CANCEL_DISABLE   BIT(_PTHREAD_CANCEL_POS)

◆ PTHREAD_CANCEL_ENABLE

#define PTHREAD_CANCEL_ENABLE   (0U << _PTHREAD_CANCEL_POS)

◆ PTHREAD_COND_DEFINE

#define PTHREAD_COND_DEFINE (   name)    pthread_cond_t name = PTHREAD_COND_INITIALIZER

Declare a pthread condition variable.

Declaration API for a pthread condition variable. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the condition variable
Deprecated:
Use PTHREAD_COND_INITIALIZER instead.

◆ PTHREAD_COND_INITIALIZER

#define PTHREAD_COND_INITIALIZER   (-1)

Declare a condition variable as initialized.

Initialize a condition variable with the default condition variable attributes.

◆ PTHREAD_CREATE_DETACHED

#define PTHREAD_CREATE_DETACHED   0

◆ PTHREAD_CREATE_JOINABLE

#define PTHREAD_CREATE_JOINABLE   1

◆ PTHREAD_MUTEX_DEFAULT

#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL

◆ PTHREAD_MUTEX_DEFINE

#define PTHREAD_MUTEX_DEFINE (   name)    pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER

Declare a pthread mutex.

Declaration API for a pthread mutex. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the mutex
Deprecated:
Use PTHREAD_MUTEX_INITIALIZER instead.

◆ PTHREAD_MUTEX_ERRORCHECK

#define PTHREAD_MUTEX_ERRORCHECK   2

◆ PTHREAD_MUTEX_INITIALIZER

#define PTHREAD_MUTEX_INITIALIZER   (-1)

Declare a mutex as initialized.

Initialize a mutex with the default mutex attributes.

◆ PTHREAD_MUTEX_NORMAL

#define PTHREAD_MUTEX_NORMAL   0

◆ PTHREAD_MUTEX_RECURSIVE

#define PTHREAD_MUTEX_RECURSIVE   1

◆ PTHREAD_ONCE_INIT

#define PTHREAD_ONCE_INIT
Value:
{ \
1, 0 \
}

◆ PTHREAD_PRIO_NONE

#define PTHREAD_PRIO_NONE   0

◆ PTHREAD_STACK_MIN

#define PTHREAD_STACK_MIN   Z_KERNEL_STACK_SIZE_ADJUST(0)

Function Documentation

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t *  attr)

◆ pthread_attr_getdetachstate()

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

◆ pthread_attr_getschedparam()

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

◆ pthread_attr_getschedpolicy()

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

◆ pthread_attr_getstack()

int pthread_attr_getstack ( const pthread_attr_t *  attr,
void **  stackaddr,
size_t *  stacksize 
)

◆ pthread_attr_getstacksize()

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

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t *  attr)

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t *  attr,
int  detachstate 
)

◆ pthread_attr_setschedparam()

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

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t *  attr,
int  policy 
)

◆ pthread_attr_setstack()

int pthread_attr_setstack ( pthread_attr_t *  attr,
void *  stackaddr,
size_t  stacksize 
)

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t *  attr,
size_t  stacksize 
)

◆ pthread_barrier_destroy()

static int pthread_barrier_destroy ( pthread_barrier_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrier_init()

static int pthread_barrier_init ( pthread_barrier_t *  b,
const pthread_barrierattr_t *  attr,
unsigned int  count 
)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrier_wait()

int pthread_barrier_wait ( pthread_barrier_t *  b)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrierattr_destroy()

static int pthread_barrierattr_destroy ( pthread_barrierattr_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_barrierattr_init()

static int pthread_barrierattr_init ( pthread_barrierattr_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_cancel()

int pthread_cancel ( pthread_t  pthread)

◆ pthread_cond_broadcast()

int pthread_cond_broadcast ( pthread_cond_t *  cv)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_destroy()

int pthread_cond_destroy ( pthread_cond_t *  cv)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_init()

int pthread_cond_init ( pthread_cond_t *  cv,
const pthread_condattr_t *  att 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_signal()

int pthread_cond_signal ( pthread_cond_t *  cv)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_timedwait()

int pthread_cond_timedwait ( pthread_cond_t *  cv,
pthread_mutex_t *  mut,
const struct timespec abstime 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_wait()

int pthread_cond_wait ( pthread_cond_t *  cv,
pthread_mutex_t *  mut 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_condattr_destroy()

static int pthread_condattr_destroy ( pthread_condattr_t *  att)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_condattr_init()

static int pthread_condattr_init ( pthread_condattr_t *  att)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1.

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_create()

int pthread_create ( pthread_t *  newthread,
const pthread_attr_t *  attr,
void *(*)(void *)  threadroutine,
void *  arg 
)

◆ pthread_detach()

int pthread_detach ( pthread_t  thread)

◆ pthread_equal()

static int pthread_equal ( pthread_t  pt1,
pthread_t  pt2 
)
inlinestatic

Compare thread IDs.

See IEEE 1003.1

◆ pthread_exit()

void pthread_exit ( void *  retval)

◆ pthread_getname_np()

int pthread_getname_np ( pthread_t  thread,
char *  name,
size_t  len 
)

Get name of POSIX thread and store in name buffer that is of size len.

Non-portable, extension function that conforms with most other definitions of this function.

Parameters
threadPOSIX thread to obtain name information
nameDestination buffer
lenDestination buffer size
Return values
0Success
ESRCHThread does not exist
EINVALName buffer is NULL
Negativevalue if kernel function error

◆ pthread_getschedparam()

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

◆ pthread_getspecific()

void * pthread_getspecific ( pthread_key_t  key)

◆ pthread_join()

int pthread_join ( pthread_t  thread,
void **  status 
)

◆ pthread_key_create()

int pthread_key_create ( pthread_key_t *  key,
void(*)(void *)  destructor 
)

◆ pthread_key_delete()

int pthread_key_delete ( pthread_key_t  key)

◆ pthread_mutex_destroy()

int pthread_mutex_destroy ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_init()

int pthread_mutex_init ( pthread_mutex_t *  m,
const pthread_mutexattr_t *  att 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_lock()

int pthread_mutex_lock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_timedlock()

int pthread_mutex_timedlock ( pthread_mutex_t *  m,
const struct timespec abstime 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_trylock()

int pthread_mutex_trylock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_unlock()

int pthread_mutex_unlock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_destroy()

static int pthread_mutexattr_destroy ( pthread_mutexattr_t *  m)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_mutexattr_getprotocol()

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

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_gettype()

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

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_init()

static int pthread_mutexattr_init ( pthread_mutexattr_t *  m)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_mutexattr_setprotocol()

int pthread_mutexattr_setprotocol ( pthread_mutexattr_t *  attr,
int  protocol 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_settype()

int pthread_mutexattr_settype ( pthread_mutexattr_t *  attr,
int  type 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_once()

int pthread_once ( pthread_once_t *  once,
void(*)(void)  initFunc 
)

◆ pthread_rwlock_destroy()

int pthread_rwlock_destroy ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_init()

int pthread_rwlock_init ( pthread_rwlock_t *  rwlock,
const pthread_rwlockattr_t *  attr 
)

◆ pthread_rwlock_rdlock()

int pthread_rwlock_rdlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_timedrdlock()

int pthread_rwlock_timedrdlock ( pthread_rwlock_t *  rwlock,
const struct timespec abstime 
)

◆ pthread_rwlock_timedwrlock()

int pthread_rwlock_timedwrlock ( pthread_rwlock_t *  rwlock,
const struct timespec abstime 
)

◆ pthread_rwlock_tryrdlock()

int pthread_rwlock_tryrdlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_trywrlock()

int pthread_rwlock_trywrlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_unlock()

int pthread_rwlock_unlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_wrlock()

int pthread_rwlock_wrlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlockattr_destroy()

static int pthread_rwlockattr_destroy ( pthread_rwlockattr_t *  attr)
inlinestatic

Destroy the read-write lock attributes object.

See IEEE 1003.1

◆ pthread_rwlockattr_init()

static int pthread_rwlockattr_init ( pthread_rwlockattr_t *  attr)
inlinestatic

initialize the read-write lock attributes object.

See IEEE 1003.1

◆ pthread_self()

pthread_t pthread_self ( void  )

Obtain ID of the calling thread.

The results of calling this API from threads not created with pthread_create() are undefined.

See IEEE 1003.1

◆ pthread_setcancelstate()

int pthread_setcancelstate ( int  state,
int *  oldstate 
)

◆ pthread_setname_np()

int pthread_setname_np ( pthread_t  thread,
const char *  name 
)

Set name of POSIX thread.

Non-portable, extension function that conforms with most other definitions of this function.

Parameters
threadPOSIX thread to set name
nameName string
Return values
0Success
ESRCHThread does not exist
EINVALName buffer is NULL
Negativevalue if kernel function error

◆ pthread_setschedparam()

int pthread_setschedparam ( pthread_t  pthread,
int  policy,
const struct sched_param *  param 
)

◆ pthread_setspecific()

int pthread_setspecific ( pthread_key_t  key,
const void *  value 
)