POSIX Thread
POSIX thread operations for the QuantumRT Real-Time Kernel.
Part of QuantumRT Real-Time Kernel.
Defines
-
PTHREAD_CREATE_JOINABLE
Joinable thread attribute.
-
PTHREAD_CREATE_DETACHED
Detached thread attribute.
-
PTHREAD_CANCEL_ENABLE
Cancel enable attribute.
-
PTHREAD_CANCEL_DISABLE
Cancel disable attribute.
-
PTHREAD_CANCEL_DEFERRED
Deferred cancel attribute.
-
PTHREAD_CANCEL_ASYNCHRONOUS
Asynchronous cancel attribute.
-
PTHREAD_PRIO_INHERIT
Priority inheritance protocol.
-
PTHREAD_PRIO_NONE
No priority protocol.
-
PTHREAD_PRIO_PROTECT
Priority protect protocol.
-
PTHREAD_MUTEX_DEFAULT
Default mutex type.
-
PTHREAD_MUTEX_ERRORCHECK
Error-checking mutex type.
-
PTHREAD_MUTEX_NORMAL
Normal mutex type.
-
PTHREAD_MUTEX_RECURSIVE
Recursive mutex type.
-
PTHREAD_MUTEX_ROBUST
Robust mutex type. Not supported.
-
PTHREAD_MUTEX_STALLED
Stalled mutex type. Not supported.
-
PTHREAD_PROCESS_SHARED
Process-shared mutex attribute. Not supported.
-
PTHREAD_PROCESS_PRIVATE
Process-private mutex attribute. Not supported.
-
PTHREAD_SCOPE_PROCESS
Process scope mutex attribute. Not supported.
-
PTHREAD_SCOPE_SYSTEM
System scope mutex attribute. Not supported.
-
PTHREAD_INHERIT_SCHED
Inherit scheduling attribute.
-
PTHREAD_EXPLICIT_SCHED
Explicit scheduling attribute.
-
PTHREAD_PRIVILEGED_NP
Privileged thread attribute.
-
PTHREAD_UNPRIVILEGED_NP
Unprivileged thread attribute.
-
PTHREAD_ONCE_INIT
Once initialization. Not supported.
-
PTHREAD_COND_INITIALIZER
Condition variable initialization. Not supported.
-
PTHREAD_MUTEX_INITIALIZER
Mutex initialization.
-
PTHREAD_RWLOCK_INITIALIZER
Read-write lock initialization. Not supported.
-
PTHREAD_NULL
Not equal to valid thread.
Functions
-
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
Lock a mutex with a timeout. If the mutex is already locked, the calling thread will block until the mutex becomes available or the specified absolute time is reached.
Error numbers:
EDEADLK: The current thread already owns the mutex and the mutex type is PTHREAD_MUTEX_ERRORCHECK.
EAGAIN: The maximum number of recursive locks for the mutex has been exceeded.
EINVAL: The mutex object is not valid.
EINVAL: The mutex was created with PTHREAD_PRIO_PROTECT and the current thread’s priority is higher than the current priority ceiling.
EINVAL: The thread would have blocked but the abstime parameter specified nanoseconds outside the valid range of [0, 999’999’999].
- Parameters:
mutex – Pointer to the mutex to lock.
abstime – Pointer to the absolute time to wait until.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy a mutex.
Error numbers:
EBUSY: The mutex object is currently in use.
- Parameters:
mutex – Pointer to the mutex to destroy.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize a mutex with specified attributes.
- Parameters:
mutex – Pointer to the mutex to initialize.
attr – Pointer to the mutex attributes. NULL for default attributes.
- Returns:
0 on success, or -1 on failure.
-
int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling)
Get the priority ceiling of a mutex.
Error numbers:
EINVAL: The mutex object is not valid.
EINVAL: The mutex protocol attribute is set to PTHREAD_PRIO_NONE.
- Parameters:
mutex – Pointer to the mutex.
prioceiling – Pointer to store the priority ceiling value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling)
Set the priority ceiling of a mutex.
Error numbers:
EINVAL: The mutex object is not valid.
EINVAL: The mutex protocol attribute is set to PTHREAD_PRIO_NONE.
EINVAL: The mutex was created with PTHREAD_PRIO_PROTECT and the current thread’s priority is higher than the current priority ceiling.
EAGAIN: The system lacked the necessary resources to change the priority ceiling.
EDEADLK: A deadlock condition was detected.
- Parameters:
mutex – Pointer to the mutex.
prioceiling – New priority ceiling value.
old_ceiling – Pointer to store the old priority ceiling value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock a mutex. If the mutex is already locked, the calling thread will block until the mutex becomes available.
Error numbers:
EDEADLK: The current thread already owns the mutex and the mutex type is PTHREAD_MUTEX_ERRORCHECK.
EAGAIN: The maximum number of recursive locks for the mutex has been exceeded.
EINVAL: The mutex object is not valid.
EINVAL: The mutex was created with PTHREAD_PRIO_PROTECT and the current thread’s priority is higher than the current priority ceiling.
- Parameters:
mutex – Pointer to the mutex to lock.
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" #include "tensorflow/lite/c/c_api.h" // Shared model and interpreter pthread_mutex_t model_lock = PTHREAD_MUTEX_INITIALIZER; TfLiteModel *model = NULL; TfLiteInterpreter *interpreter = NULL; int main(void) { TfLiteInterpreterOptions *options; pthread_t t_cam; pthread_t t_mic; model = TfLiteModelCreateFromFile("/flash/model.tflite"); options = TfLiteInterpreterOptionsCreate(); TfLiteInterpreterOptionsSetNumThreads(options, 1); interpreter = TfLiteInterpreterCreate(model, options); TfLiteInterpreterAllocateTensors(interpreter); pthread_create(&t_cam, NULL, inference_thread, camera_input); pthread_create(&t_mic, NULL, inference_thread, mic_input); } void *inference_thread(void *arg) { TfLiteTensor *input; TfLiteTensor *output; const float *input_data = (const float*)arg; for (;;) { // Multiple inference threads share the same model and interpreter // Protect the interpreter and tensor buffer during inference pthread_mutex_lock(&model_lock); input = TfLiteInterpreterGetInputTensor(interpreter, 0); memcpy(input->data.f, input_data, input->bytes); TfLiteInterpreterInvoke(interpreter); output = TfLiteInterpreterGetOutputTensor(interpreter, 0); handle_results(output); // Unlock the model and interpreter for other threads pthread_mutex_unlock(&model_lock); } return NULL; }
-
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Try to lock a mutex. If the mutex is already locked, the function will return immediately.
Error numbers:
EBUSY: The mutex is already locked by another thread.
EDEADLK: The current thread already owns the mutex and the mutex type is PTHREAD_MUTEX_ERRORCHECK.
EINVAL: The mutex object is not valid.
EAGAIN: The maximum number of recursive locks for the mutex has been exceeded.
EINVAL: The mutex was created with PTHREAD_PRIO_PROTECT and the current thread’s priority is higher than the current priority ceiling.
- Parameters:
mutex – Pointer to the mutex to lock.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Unlock a mutex.
Error numbers:
EPERM: The current thread does not own the mutex.
EINVAL: The mutex object is not valid.
- Parameters:
mutex – Pointer to the mutex to unlock.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
- Parameters:
attr – Pointer to the mutex attributes to destroy.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize a mutex attributes object with default values.
The default protocol is PTHREAD_PRIO_NONE. Error numbers:
EINVAL: The mutex attributes object is not valid.
- Parameters:
attr – Pointer to the mutex attributes to initialize.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling)
Get the priority ceiling attribute from a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
prioceiling – Pointer to store the priority ceiling value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling)
Set the priority ceiling attribute in a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
prioceiling – New priority ceiling value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol)
Get the protocol attribute from a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
EINVAL: The protocol value is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
protocol – Pointer to store the protocol value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
Set the protocol attribute in a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
EINVAL: The protocol value is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
protocol – New protocol value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
Get the type attribute from a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
EINVAL: The type value is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
type – Pointer to store the type value.
- Returns:
0 on success, or an error number on failure.
-
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
Set the type attribute in a mutex attributes object.
Error numbers:
EINVAL: The mutex attributes object is not valid.
EINVAL: The type value is not valid.
- Parameters:
attr – Pointer to the mutex attributes object.
type – New type value.
- Returns:
0 on success, or an error number on failure.
Not supported.
- Returns:
Not supported.
- Returns:
-
int pthread_mutexattr_getrobust(const pthread_mutexattr_t *attr, int *robust)
Not supported.
- Returns:
-
int pthread_mutexattr_setrobust(pthread_mutexattr_t *attr, int robust)
Not supported.
- Returns:
-
int pthread_mutex_consistent(pthread_mutex_t *mutex)
Not supported.
- Returns:
-
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
Create a new thread.
- Parameters:
thread – Pointer to the thread handle. NULL if not needed.
attr – Pointer to the thread attributes. NULL for default attributes.
start_routine – Pointer to the function to be executed by the thread.
arg – Argument to be passed to the thread function.
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" #include "stdio.h" void *thread_a(void *arg) { void *ret; pthread_t thread; if (pthread_create(&thread, NULL, thread_b, "thread_b entered") == -1) { exit(2); } if (pthread_join(thread, ret) == -1) { exit(3); } printf("thread_b() exited with return value %s\r\n", (char *)ret); return NULL; } void *thread_b(void *arg) { char *ret = "thread_b exited\r\n"; printf("thread_b() entered with argument %s\r\n", (char *)arg); // Perform thread operations... return ret; }
-
void pthread_cleanup_push(void (*routine)(void*), void *arg)
Push a cleanup handler onto the thread’s cleanup stack.
- Parameters:
routine – Pointer to the cleanup handler function.
arg – Argument to be passed to the cleanup handler.
#include "pthread.h" pthread_mutex_t lock; void lock_cleanup(void *arg) { pthread_mutex_unlock((pthread_mutex_t *)arg); } void *thread(void *arg) { // Even if the thread is cancelled while in the critical, // section the lock will be unlocked. pthread_mutex_t *lock = (pthread_mutex_t *)arg; pthread_cleanup_push(lock_cleanup, (void *)lock); do_critical_section_work(); pthread_cleanup_pop(1); // Execute cleanup handler return NULL; }
-
void pthread_cleanup_pop(int execute)
Pop a cleanup handler from the thread’s cleanup stack.
See also
pthread_cleanup_push() for example.
- Parameters:
execute – If non-zero, the cleanup handler is executed.
-
int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
Get the scheduling parameters of the specified thread.
- Parameters:
thread – The thread to query.
policy – Pointer to a location where the scheduling policy will be stored.
param – Pointer to a location where the scheduling parameters will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
Set the scheduling policy and parameters of the specified thread. May trigger a context switch if the new priority is higher than the current priority.
- Parameters:
thread – The thread to set the scheduling policy and parameters for.
policy – The new scheduling policy. One of:
param – Pointer to a structure containing the new scheduling parameters.
- Returns:
0 on success, or an error number on failure.
-
int pthread_setschedprio(pthread_t thread, int prio)
Set thread scheduling priority. May trigger a context switch if the new priority is higher than the current priority.
- Parameters:
thread – The thread to set the priority for.
prio – The new priority value.
- Returns:
0 on success, or an error number on failure.
-
void pthread_exit(void *value_ptr)
Terminate the calling thread. Same as returning from the thread function.
void *thread(void *arg) { // Perform thread operations... pthread_exit((void *)0); }
- Parameters:
value_ptr – Pointer to the return value of the thread.
-
int pthread_equal(pthread_t t1, pthread_t t2)
Compare two thread identifiers.
- Parameters:
t1 – First thread identifier.
t2 – Second thread identifier.
- Returns:
0 if equal, non-zero otherwise.
-
pthread_t pthread_self(void)
Get the calling thread’s identifier.
- Returns:
The calling thread’s ID.
-
int pthread_cancel(pthread_t thread)
Request cancellation of the specified thread.
- Parameters:
thread – The thread to cancel.
- Returns:
0 on success, or an error number on failure.
void *worker_thread(void *arg) { pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); // Simulate work // Create a cancellation point pthread_testcancel(); return NULL; } void *thread(void *arg) { struct timespec ts = {0, 100000000}; // Let the worker thread run for a while nanosleep(&ts, NULL); pthread_cancel(worker); pthread_join(worker, NULL); return NULL; }
-
int pthread_setcancelstate(int state, int *oldstate)
Set the cancelability state of the calling thread.
- Parameters:
state – One of the cancelability states:
oldstate – Pointer to a location where the old state will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_setcanceltype(int type, int *oldtype)
Set the cancelability type of the calling thread.
See also
pthread_cancel() for example.
- Parameters:
type – One of the cancelability types:
oldtype – Pointer to a location where the old type will be stored.
- Returns:
0 on success, or an error number on failure.
-
void pthread_testcancel(void)
Create a cancellation point in the calling thread. A cancellation point is location where the control flow is returned back to the scheduler.
See also
pthread_cancel() for example.
-
int pthread_join(pthread_t thread, void **value_ptr)
Wait for the specified thread to terminate.
See also
pthread_create() for example.
- Parameters:
thread – The thread to wait for.
value_ptr – Pointer to a location where the return value of the thread will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_detach(pthread_t thread)
Detach the specified thread. A detached thread’s resources are automatically released upon termination.
- Parameters:
thread – The thread to detach.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
#include "pthread.h" void *thread(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_create(NULL, &attr, new_thread, NULL); return NULL; }
- Parameters:
attr – Pointer to the thread attributes object to initialize.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_destroy(pthread_attr_t *attr)
Destroy a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object to destroy.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched)
Get the inherit scheduling attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
inheritsched – Pointer to a location where the inherit scheduling attribute will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)
Set the inherit scheduling attribute in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
ENOTSUP: Attempt to set an unsupported inherit scheduling attribute.
- Parameters:
attr – Pointer to the thread attributes object.
inheritsched – The inherit scheduling attribute to set. One of:
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get the detach state attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
detachstate – Pointer to a location where the detach state attribute will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set the detach state attribute in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
detachstate – The detach state attribute to set. One of:
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" void *thread(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(NULL, &attr, new_thread, NULL); return NULL; }
-
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
Get the stack address and size attributes from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
stackaddr – Pointer to the stack base address.
stacksize – Pointer to a size_t variable where the stack size will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
Set the stack address and size attributes in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
stackaddr – Pointer to the stack base address.
stacksize – Stack size.
- Returns:
0 on success, or an error number on failure.
unsigned char myStack[1024u]; void *thread_a(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstack(&attr, myStack, sizeof(myStack)); pthread_create(NULL, &attr, thread_b, NULL); return NULL; } void *thread_b(void *arg) { // Thread implementation return NULL; }
-
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
Get the stack size attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
stacksize – Pointer to a size_t variable where the stack size will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
Set the stack size attribute in a thread attributes object. pthread_create() will allocate a stack with at least this size for the new thread. The allocated stack size is rounded up to the nearest power of two.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
stacksize – Stack size.
- Returns:
0 on success, or an error number on failure.
void *thread_a(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); // Set thread attributes as needed pthread_attr_setstacksize(&attr, sizeof(myStack)); // No need to provide stack address, // it will be allocated by pthread_create() pthread_create(NULL, &attr, thread_b, NULL); return NULL; } void *thread_b(void *arg) { // Thread implementation return NULL; }
-
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
Get the scheduling policy attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
policy – Pointer to a location where the scheduling policy attribute will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
Set the scheduling policy attribute in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
ENOTSUP: Invalid scheduling policy value.
- Parameters:
attr – Pointer to the thread attributes object.
policy – The scheduling policy attribute to set. One of:
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" void *thread(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); // Default policy is SCHED_FIFO pthread_attr_setschedpolicy(&attr, SCHED_RR); pthread_create(NULL, &attr, new_thread, NULL); return NULL; }
-
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
Get the scheduling parameters attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
EINVAL: The scheduling parameters pointer is NULL.
- Parameters:
attr – Pointer to the thread attributes object.
param – Pointer to a location where the scheduling parameters will be stored.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
Set the scheduling parameters attribute in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
EINVAL: The scheduling parameters pointer is NULL.
ENOTSUP: Invalid scheduling priority value.
- Parameters:
attr – Pointer to the thread attributes object.
param – Pointer to the scheduling parameters to set.
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" void *thread(void *arg) { struct sched_param param; pthread_attr_t attr; pthread_attr_init(&attr); param.sched_priority = 10; pthread_attr_setschedparam(&attr, ¶m); pthread_create(NULL, &attr, new_thread, NULL); return NULL; }
-
int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
Not supported.
- Returns:
-
int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
Not supported.
- Returns:
-
int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
Not supported.
- Returns:
-
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
Not supported.
- Returns:
-
int pthread_attr_getname_np(const pthread_attr_t *attr, char *name, size_t len)
Get the name attribute from a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
name – Pointer to a buffer to store the thread name.
len – Length of the buffer.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setname_np(pthread_attr_t *attr, const char *name)
Set the name attribute in a thread attributes object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attributes object.
name – The name to set for the thread.
- Returns:
0 on success, or an error number on failure.
-
int pthread_setname_np(pthread_t thread, const char *name)
Set the name of the specified thread.
Error numbers:
EINVAL: The thread object is not valid.
- Parameters:
thread – The thread to set the name of.
name – The new name for the thread.
- Returns:
0 on success, or an error number on failure.
-
int pthread_getname_np(pthread_t thread, char *name, size_t len)
Get the name of the specified thread.
Error numbers:
EINVAL: The thread object is not valid.
- Parameters:
thread – The thread to get the name of.
name – Pointer to a buffer to store the thread name.
len – Length of the buffer.
- Returns:
0 on success, or an error number on failure.
-
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
Not supported.
- Returns:
-
void *pthread_getspecific(pthread_key_t key)
Not supported.
- Returns:
-
int pthread_setspecific(pthread_key_t key, const void *value)
Not supported.
- Returns:
-
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
Not supported.
- Returns:
-
int pthread_key_delete(pthread_key_t key)
Not supported.
- Returns:
-
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
Not supported.
- Returns:
-
int pthread_spin_destroy(pthread_spinlock_t *lock)
Not supported.
- Returns:
-
int pthread_spin_init(pthread_spinlock_t *lock, int pshared)
Not supported.
- Returns:
-
int pthread_spin_lock(pthread_spinlock_t *lock)
Not supported.
- Returns:
-
int pthread_spin_trylock(pthread_spinlock_t *lock)
Not supported.
- Returns:
-
int pthread_spin_unlock(pthread_spinlock_t *lock)
Not supported.
- Returns:
-
int pthread_barrier_destroy(pthread_barrier_t *barrier)
Not supported.
- Returns:
-
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count)
Not supported.
- Returns:
-
int pthread_barrier_wait(pthread_barrier_t *barrier)
Not supported.
- Returns:
-
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
Not supported.
- Returns:
-
int pthread_barrierattr_init(pthread_barrierattr_t *attr)
Not supported.
- Returns:
Not supported.
- Returns:
Not supported.
- Returns:
-
int pthread_rwlock_clockrdlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime)
Not supported.
- Returns:
-
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Not supported.
- Returns:
-
int pthread_rwlock_clockwrlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime)
Not supported.
- Returns:
-
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Not supported.
- Returns:
-
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
Not supported.
- Returns:
-
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
Not supported.
- Returns:
-
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
Not supported.
- Returns:
-
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
Not supported.
- Returns:
Not supported.
- Returns:
Not supported.
- Returns:
-
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Not supported.
- Returns:
-
int pthread_cond_destroy(pthread_cond_t *cond)
Not supported.
- Returns:
-
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Not supported.
- Returns:
-
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
Not supported.
- Returns:
-
int pthread_cond_signal(pthread_cond_t *cond)
Not supported.
- Returns:
-
int pthread_cond_broadcast(pthread_cond_t *cond)
Not supported.
- Returns:
-
int pthread_condattr_init(pthread_condattr_t *attr)
Not supported.
- Returns:
-
int pthread_condattr_destroy(pthread_condattr_t *attr)
Not supported.
- Returns:
-
int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
Not supported.
- Returns:
-
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
Not supported.
- Returns:
Not supported.
- Returns:
Not supported.
- Returns:
-
int pthread_attr_settimeslice_np(pthread_attr_t *attr, const struct timespec *timeSlice)
Set the time slice for a thread attribute object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
timeSlice – Pointer to a timespec structure that specifies the time slice duration.
- Returns:
0 on success, or an error number on failure.
-
int pthread_attr_setprivilege_np(pthread_attr_t *attr, int privilege)
Set the privilege level from a thread attribute object.
Error numbers:
EINVAL: The thread attributes object is not valid.
- Parameters:
attr – Pointer to the thread attribute object.
privilege – One of the following values:
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" void *thread(void *arg) { pthread_attr_t attr; pthread_attr_init(&attr); // We want to create a privileged thread in this case, // but the default value is unprivileged. pthread_attr_setprivilege_np(&attr, PTHREAD_PRIVILEGED_NP); pthread_create(NULL, &attr, new_thread, NULL); return NULL; }
-
int pthread_dropprivilege_np(void)
Drop the privilege level of the calling thread to unprivileged.
- Returns:
0 on success, or an error number on failure.
#include "pthread.h" int main(void) { ... qrt_mpu_init(&__ROM_BASE, (u32)&__ROM_SIZE, &__RAM_BASE, (u32)&__RAM_SIZE, &__ROM_PRIV_BASE, (u32)&__ROM_PRIV_SIZE, &__RAM_PRIV_BASE, (u32)&__RAM_PRIV_SIZE); qrt_kernelstart(); // Main thread is created as privileged, // drop privilege if not needed. pthread_dropprivilege_np(); ... }