Thread-private data, thread-specific data, and thread local storage

Threads cannot share certain resources. Data that threads cannot share between themselves are called thread-private data. Data that threads cannot share between themselves can be defined using either thread-specific data or thread local storage.

The IBM® i operating system defines the following resources as thread-private data.
  • Thread identifier

    The unique integral number that can be used to identify the thread.

  • Priority

    IBM i supports specification of a thread priority, which determines the relative importance of one thread to other threads in the job. The thread priority is defined to be a delta value to the job's priority. IBM i adds the thread's priority to the job's priority, and the result can never exceed the job's priority. If you adjust the job's priority, the thread's priority is adjusted relative to the new job priority. The default thread priority value is zero. This results in a thread that has the same priority as the job.

  • Security information

    Security information, including user and group profiles, is maintained on a per-thread basis. When a thread creates a new thread, the new thread inherits the security information from the thread that created it.

  • Library list

    Library list information is maintained on a per-thread basis. When a thread creates a new thread, the new thread inherits the library list information from the thread that created it.

  • Signal blocking mask

    The signal blocking mask identifies the set of asynchronous signals to be blocked from delivery to the thread. When a thread creates a new thread, the new thread inherits the signal blocking mask of the thread that created it.

  • Call stack

    The call stack contains data about the program flow or procedure call flow in a thread. The stack, along with automatic storage, is allocated for each thread created.

  • Automatic storage

    Automatic storage is for variables that are local to the function.

  • Errno variable

    This program variable is used to return the result of a C or POSIX system call. Errno is a function call that returns the most recent result for a function call in the thread.

Thread-specific data is different from thread-private data. The threads implementation defines the thread-private data, while the application defines the thread-specific data. Threads do not share thread-specific storage (it is specific to a thread), but all functions within that thread can access it. Typically, a key indexes thread-specific storage. The key is a global value that is visible to all threads. It is used to retrieve the thread-specific value of the storage associated with that key.

Data that is defined using thread local storage is similar to thread-specific data. Threads do not share thread local storage, but all functions within a thread can access the storage for that thread. Thread local storage is different from thread-specific data in that thread local storage is managed by the language environment, whereas thread-specific data is managed by the application.