directive
synchronized/1
ï
Descriptionï
synchronized(Name/Arity)
synchronized((Name/Arity, ...))
synchronized([Name/Arity, ...])
synchronized(Name//Arity)
synchronized((Name//Arity, ...))
synchronized([Name//Arity, ...])
Declares synchronized predicates and synchronized grammar rule non-terminals. The most common use is for predicates that have side effects (e.g., asserting or retracting clauses for a dynamic predicate) in multi-threaded applications. A synchronized predicate (or synchronized non-terminal) is protected by a mutex in order to allow for thread synchronization when proving a call to the predicate (or non-terminal).
All predicates (and non-terminals) declared in the same synchronized directive share the same mutex. In order to use a separate mutex for each predicate (non-terminal) so that they are independently synchronized, a per-predicate synchronized directive must be used.
Warning
Declaring a predicate synchronized implicitly makes it deterministic. When using a single-threaded backend Prolog compiler, calls to synchronized predicates behave as wrapped by the standard once/1 meta-predicate.
Note that synchronized predicates cannot be declared dynamic (when necessary, declare the predicates updating the dynamic predicates as synchronized).
Template and modesï
synchronized(+predicate_indicator_term)
synchronized(+non_terminal_indicator_term)
Examplesï
:- synchronized(db_update/1).
:- synchronized((write_stream/2, read_stream/2)).
:- synchronized([add_to_queue/2, remove_from_queue/2]).
See also