Threads and Dynamic Predicates

Besides queues threads can share and exchange data using dynamic predicate.

s. The multi-threaded version knows about two types of dynamic predicates. By default, a predicate declared dynamic (see dynamic//11) is shared by all threads. Each thread may assert, retract and run the dynamic predicate. Synchronisation inside Prolog guarantees the consistency of the predicate. Updates are logical: visible clauses are not affected by assert/retract after a query started on the predicate. In many cases primitive from thread synchronisation should be used to ensure application invariants on the predicate are maintained.

Besides shared predicates, dynamic predicates can be declared with the thread_local//11 directive. Such predicates share their attributes, but the clause-list is different in each thread.