pthread_create -- create a thread


       #include <rtl_sched.h>

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


This function is an RTLinux version of standard POSIX threads function. pthread_create creates a realtime thread that will have attributes given by attr, and that begins executing function start_routine(arg ). If the attribute is NULL, default attributes are used. The thread attributes in RTLinux are extended to allow thread creation on specific processors (pthread_attr_setcpu_np), to enable FPU operations in the created thread (pthread_attr_setfp_np).

The standard thread attribute setting functions supported include pthread_attr_setschedparam, pthread_attr_setdetachstate, pthread_attr_setstacksize, pthread_attr_setstackaddr. The last call is to allow users to allocate memory for thread stacks -- so that threads can be created in RT operating mode by making use of pre-allocated memory. pthread_join should be used to synchronize freeing of thread resources including memory. For example if a thread is created with user allocated stack via pthread_attr_setstackaddr, that memory can only be safely reallocated after a pthread_join.


pthread_create returns 0 on success and a non-zero error code on error.



Either not enough memory, or PTHREAD_THREADS_MAX would be exceeded, or pthread_create is called from RT-thread context and preallocated stack use is not specified.


Bad attributes.


Victor Yodaiken (


In the absense of preallocated stack (via pthread_attr_setstackaddr), the use of this function is restricted to the Linux init_module() or cleanup_module() context.


UNIX spec pthread_create(3), pthread_attr_setstackaddr(3), pthread_attr_setstacksize(3), pthread_join(3), pthread_make_periodic_np(3), pthread_attr_setcpu_np(3), pthread_attr_getcpu_np(3), pthread_attr_setfp_np(3)

2001 FSMLabs Inc.

All rights reserved.