thread_local/1

thread_local( +Functor/Arity)*

related to the dynamic//11 directive. It tells the system that the predicate may be modified using assert//11, retract//11, etc, during execution of the program. Unlike normal shared dynamic data however each thread has its own clause-list for the predicate. As a thread starts, this clause list is empty. If there are still clauses as the thread terminates these are automatically reclaimed by the system. The thread_local property implies the property dynamic.

Thread-local dynamic predicates are intended for maintaining thread-specific state or intermediate results of a computation.

It is not recommended to put clauses for a thread-local predicate into a file as in the example below as the clause is only visible from the thread that loaded the source-file. All other threads start with an empty clause-list.


 :- thread_local @ref fooU2fU_1 "foo//1" 1.

 foo(gnat).