Availability:built-in
thread_wait(:Goal,
:Options)Block execution of the calling thread until Goal becomes
true. The application must be prepared to handle spurious calls to Goal,
i.e., more calls than asked for based on the Options list. A
possible exception in Goal is propagated and thus terminates
thread_wait/2.
The wait is associated with a module. This module is derived from the
Options argument.
The Options list specifies when Goal is
re-evaluated and optionally when the call terminates due to a timeout.
- deadline(+AbsTime)
- timeout(+Time)
- Timeout and deadline handling. See thread_get_message/3
for details. This predicate fails when it terminates due to one of these
options.
- retry_every(+Time)
- Retry goal every Time seconds regardless of whether an event
happened. The default is 1 second. This ensures that signals (see thread_signal/2)
and time limits are respected with an optional delay.204Some
operating systems process such signals immediately, while others only
check for such events synchronously.
- db(+Boolean)
- Wakeup on arbitrary changes to any dynamic predicate that is defined in
the associated module. This is the default if
wait_preds(+Preds)
is not provided.
- wait_preds(+List)
- Only call Goal if at least one of the predicates in
List has been modified. Each element of List is a predicate
indicator (Name/Arity or
Name//Arity that is resolved to a predicate in the module this
wait is associated with. If the element is
+
(PI)
205Note
that +p/1
is read as /(+(p),1)., Goal is only triggered if
a clause was added (assert/1).
If the element is -
(PI)
, Goal is
only triggered if a clause was retracted (retract/1
or
erase/1).
Default is to wakeup on both assert and retract.
- modified(-List)
- The List variable normally also appears in Goal
and is unified with a list of predicates from the
wait_preds
option that have been modified.
List must be unbound at entry.
- module(+Module)
- Specifies the module to act on explicitly.
The execution of Goal is synchronized between all threads
calling this predicate on the same module, changes to dynamic predicates
in this module and calls to thread_update/2
on the same module.
This predicate raises a permision_error
exception when
called recursively or called from inside a transaction. See
section 4.14.1.2 for
details about interaction with transactions.