thr_create(3scl)thr_create(3scl)NAMEthr_create - Creates a thread.
LIBRARY
SCL Threads Library (libthread.so)
SYNOPSIS
#include <thread.h>
int thr_create(
void *stack_base,
size_t stack_size,
void *(*start_routine)(void *),
void *arg,
long flags,
thread_t *new_thread );
PARAMETERS
Address for the base of the thread's stack. Size of the thread's
stack. Function executed as the new thread's start-routine. Address
value copied and passed to the thread's start routine. Specifying
attributes for the new thread. Holds the identifier of the newly-cre‐
ated thread.
DESCRIPTION
This routine creates a thread.
The stack_base and stack_size parameters define the new thread's stack
attributes. If they are NULL and 0 respectively then default values
will be used.
The flags parameter is a union of thread attribute values, which are:
Specifies that the thread is to contend among system-wide resources.
Specifies that the thread is a daemon thread. A process will exit when
the last non-daemon thread exits. Specifies that the thread is not
joinable. Specifies that the thread concurrency is to be increased.
Specifies that the new thread's execution is to be suspended until
another thread calls thr_continue(3scl) on it.
Non-detached, non-daemon threads should be joined by calling
thr_join(3scl) to enable the thread library to clean-up after the
thread.
SCL IMPLEMENTATION NOTESthr_create(3scl) is essentially implemented by calling pthread_cre‐
ate(3), though several other library and system routines may also be
called.
pthread_create(3) takes a pthread_attr_t argument to specify the param‐
eters of the new thread; thus thr_create(3scl) initializes, sets, uses
and destroys a pthread_attr_t object.
The SCL implementation of thr_create() makes a newly created thread
first execute an internal routine called stl_thread_start_rtn(). And
when a thread terminates, it executes other internal routines. These
routines provide the implementation of create-suspended threads and
daemon threads. These internal routines may be evident when debugging:
e.g. when examining a thread's call-stack.
The flags attributes of THR_BOUND and THR_NEW_LWP which affect thread
scheduling on Solaris are implemented as calls to
pthread_attr_setscope( PTHREAD_SCOPE_SYSTEM ) and pthread_setconcur‐
rency( pthread_getconcurrency() + 1 ) respectively. However, the under‐
lying POSIX thread library does its own thread management, and may
ignore these values. This may cause a different thread scheduling be‐
haviour to be observed when compared to Solaris. Applications should
not rely on thread scheduling for thread synchronization: explicit
thread synchronization mechanisms, such as mutexes and condition vari‐
ables, should be used instead.
Note that the thread_t type on Tru64 UNIX is a 64-bit address, whereas
on Solaris it is a 32-bit integer. See the Solaris Compatibility
Libraries User's Guide for details of what affect this might have on
applications which display the thread identifier.
RETURN VALUES
If an error condition occurs, this routine returns an integer value
indicating the type of error.
Additional error return information may be written to the SCL error
log. Refer to scl_error_log(4scl) for details.
Possible return values are as follows: Successful completion. Or:
An internal implementation error occurred, but a new thread has been
created. Refer to the SCL errorlog for additional information. The
stack_size parameter is greater than 0 and less than the value returned
by thr_min_stack(3scl). Or:
An internal implementation error occurred. Refer to the SCL errorlog
for additional information. The system lacks the necessary resources
to create another thread, or the system-imposed limit on the total num‐
ber of threads under execution by a single user is exceeded. Or:
An internal implementation error occurred. Refer to the SCL errorlog
for additional information.
ERRORS
None.
RELATED INFORMATION
Functions: pthread_attr_setscope(3), pthread_create(3),
pthread_join(3), pthread_setconcurrency(3), scl_intro(3scl),
scl_thread_intro(3scl), thr_join(3scl), thr_min_stack(3scl)
Files: scl_error_log(4scl)
Manuals: Solaris Compatibility Libraries User's Guide
thr_create(3scl)