2013-03-14 08:07:42 +01:00
|
|
|
@node POSIX Threads
|
2013-09-23 22:13:47 +02:00
|
|
|
@c @node POSIX Threads, Internal Probes, Cryptographic Functions, Top
|
2013-03-14 08:07:42 +01:00
|
|
|
@chapter POSIX Threads
|
|
|
|
@c %MENU% POSIX Threads
|
2013-03-15 04:58:54 +01:00
|
|
|
@cindex pthreads
|
2013-03-14 08:07:42 +01:00
|
|
|
|
|
|
|
This chapter describes the @glibcadj{} POSIX Thread implementation.
|
|
|
|
|
|
|
|
@menu
|
|
|
|
* Thread-specific Data:: Support for creating and
|
|
|
|
managing thread-specific data
|
2013-06-15 08:57:40 +02:00
|
|
|
* Non-POSIX Extensions:: Additional functions to extend
|
|
|
|
POSIX Thread functionality
|
2013-03-14 08:07:42 +01:00
|
|
|
@end menu
|
|
|
|
|
|
|
|
@node Thread-specific Data
|
|
|
|
@section Thread-specific Data
|
|
|
|
|
|
|
|
The @glibcadj{} implements functions to allow users to create and manage
|
|
|
|
data specific to a thread. Such data may be destroyed at thread exit,
|
|
|
|
if a destructor is provided. The following functions are defined:
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
|
|
|
|
@item int pthread_key_create (pthread_key_t *@var{key}, void (*@var{destructor})(void*))
|
|
|
|
Create a thread-specific data key for the calling thread, referenced by
|
|
|
|
@var{key}.
|
|
|
|
|
|
|
|
Objects declared with the C++11 @code{thread_local} keyword are destroyed
|
|
|
|
before thread-specific data, so they should not be used in thread-specific
|
|
|
|
data destructors or even as members of the thread-specific data, since the
|
|
|
|
latter is passed as an argument to the destructor function.
|
|
|
|
|
|
|
|
@item int pthread_key_delete (pthread_key_t @var{key})
|
|
|
|
Destroy the thread-specific data @var{key} in the calling thread. The
|
|
|
|
destructor for the thread-specific data is not called during destruction, nor
|
|
|
|
is it called during thread exit.
|
|
|
|
|
|
|
|
@item void *pthread_getspecific (pthread_key_t @var{key})
|
|
|
|
Return the thread-specific data associated with @var{key} in the calling
|
|
|
|
thread.
|
|
|
|
|
|
|
|
@item int pthread_setspecific (pthread_key_t @var{key}, const void *@var{value})
|
|
|
|
Associate the thread-specific @var{value} with @var{key} in the calling thread.
|
|
|
|
|
|
|
|
@end table
|
2013-06-15 08:57:40 +02:00
|
|
|
|
|
|
|
@node Non-POSIX Extensions
|
|
|
|
@section Non-POSIX Extensions
|
|
|
|
|
|
|
|
In addition to implementing the POSIX API for threads, @theglibc{} provides
|
|
|
|
additional functions and interfaces to provide functionality not specified in
|
|
|
|
the standard.
|
|
|
|
|
|
|
|
@menu
|
|
|
|
* Default Thread Attributes:: Setting default attributes for
|
|
|
|
threads in a process.
|
|
|
|
@end menu
|
|
|
|
|
|
|
|
@node Default Thread Attributes
|
|
|
|
@subsection Setting Process-wide defaults for thread attributes
|
|
|
|
|
|
|
|
@Theglibc{} provides non-standard API functions to set and get the default
|
|
|
|
attributes used in the creation of threads in a process.
|
|
|
|
|
|
|
|
@deftypefun int pthread_getattr_default_np (pthread_attr_t *@var{attr})
|
|
|
|
Get the default attribute values and set @var{attr} to match. This
|
|
|
|
function returns @math{0} on success and a non-zero error code on
|
|
|
|
failure.
|
|
|
|
@end deftypefun
|
|
|
|
|
2013-10-04 13:49:11 +02:00
|
|
|
@deftypefun int pthread_setattr_default_np (pthread_attr_t *@var{attr})
|
2013-06-15 08:57:40 +02:00
|
|
|
Set the default attribute values to match the values in @var{attr}. The
|
|
|
|
function returns @math{0} on success and a non-zero error code on failure.
|
|
|
|
The following error codes are defined for this function:
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@item EINVAL
|
|
|
|
At least one of the values in @var{attr} does not qualify as valid for the
|
|
|
|
attributes or the stack address is set in the attribute.
|
|
|
|
@item ENOMEM
|
|
|
|
The system does not have sufficient memory.
|
|
|
|
@end table
|
|
|
|
@end deftypefun
|