Name: threadprivate | Association: none |
Category: declarative | Properties: default |
|
Arguments
threadprivate(list) Name | Type | Properties |
list | list of variable list item type | |
|
Semantics
The threadprivate directive specifies that variables are replicated, with each thread having its own copy. Unless otherwise specified, each copy of a threadprivate variable is initialized once, in the manner specified by the program, but at an unspecified point in the program prior to the first reference to that copy. The storage of all copies of a threadprivate variable is freed according to how static variables are handled in the base language, but at an unspecified point in the program.
The content of a threadprivate variable can change across a task scheduling point if the executing thread switches to another task that modifies the variable. For more details on task scheduling, see Section 1.3 and Chapter 12.
In parallel regions, references by the primary thread are to the copy of the variable in the thread that encountered the parallel region.
During a sequential part, references are to the initial thread’s copy of the variable. The values of data in the initial thread’s copy of a threadprivate variable are guaranteed to persist between any two consecutive references to the variable in the program, provided that no teams construct that is not nested inside of a target construct is encountered between the references and that the initial thread is not executing code inside of a teams region. For initial threads that are executing code inside of a teams region, the values of data in the copies of a threadprivate variable of those initial threads are guaranteed to persist between any two consecutive references to the variable inside that teams region.
The values of data in the threadprivate variables of threads that are not initial threads are guaranteed to persist between two consecutive active parallel regions only if all of the following conditions hold:
If these conditions all hold, and if a threadprivate variable is referenced in both regions, then threads with the same thread number in their respective regions reference the same copy of that variable.
If a threadprivate variable or a variable in a threadprivate common block is not affected by any copyin clause that appears on the corresponding construct of the first parallel region in which it is referenced, the thread’s copy of the variable inherits the declared type parameter and the default parameter values from the original variable. The variable or any subobject of the variable is initially defined or undefined according to the following rules:
If it does not have either the POINTER or the ALLOCATABLE attribute:
Restrictions
Restrictions to the threadprivate directive are as follows:A program in which an untied task accesses threadprivate storage is non-conforming.
Cross References