POSIX Threads
*************

This chapter describes the glibcadj POSIX Thread implementation.

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:

int pthread_key_create (pthread_key_t *KEY, void (*DESTRUCTOR)(void*))
     Create a thread-specific data key for the calling thread, referenced by KEY.

     Objects declared with the C++11 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.

int pthread_key_delete (pthread_key_t KEY)
     Destroy the thread-specific data KEY in the calling thread.  The destructor for the thread-specific data is not called during destruction, nor is it called during thread exit.

void *pthread_getspecific (pthread_key_t KEY)
     Return the thread-specific data associated with KEY in the calling thread.

int pthread_setspecific (pthread_key_t KEY, const void *VALUE)
     Associate the thread-specific VALUE with KEY in the calling thread.

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.

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.

 -- Function: int pthread_getattr_default_np (pthread_attr_t *ATTR)
     Get the default attribute values and set ATTR to match.  This function returns 0 on success and a non-zero error code on failure.

 -- Function: int pthread_getattr_default_np (pthread_attr_t *ATTR)
     Set the default attribute values to match the values in ATTR.  The function returns 0 on success and a non-zero error code on failure. The following error codes are defined for this function:

     EINVAL
          At least one of the values in ATTR does not qualify as valid for the attributes or the stack address is set in the attribute.

     ENOMEM
          The system does not have sufficient memory.