Thread-local class variables

A thread-local variable is instantiated per traced thread the first time it issues an action block that assigns a value to the variable. Once created, the thread-local variable exists as long as the Vue script is active and the traced thread does not exit. The value of the thread-local variable is thread-specific and retained across executions of any of the clauses of the same program. In other words, variables of this class are visible everywhere within the Vue script. However, each thread that issues the Vue script obtains its own copy of these variables and the variables in each such copy are accessible and modifiable anywhere within the script only by the thread that instantiated them.

A thread-local variable is distinguished by using the thread: prefix. For example, thread:count indicates a thread-local variable. You can also declare thread-local variables using the __thread declaration statement in which case the thread: prefix can be omitted with the following one exception.

You can use a thread-local variable in the predicate section of a Vue clause even before it is instantiated. Predicates with un-instantiated thread-local variables are always evaluated to a value of FALSE. When used in the predicate section, the thread: prefix must always be included to identify it as a thread-local variable.

The following script is an example of the __thread declaration statement:

	__thread int i;      /* Explicit declaration */
	thread:j = 0;        /* Implicit declaration */
Note: Although you can declare thread-locals inside the @@BEGIN and @@END probes, any other references to them in these special probes can produce undefined behavior. A declaration statement by itself does not cause the thread-local variable to be instantiated.