Logtalk reference manual
Predicate directive: synchronized/1

synchronized/1

Description

synchronized(Functor/Arity)
synchronized((Functor1/Arity1, Functor2/Arity2, ...))
synchronized([Functor1/Arity1, Functor2/Arity2, ...])

synchronized(Functor//Arity)
synchronized((Functor1//Arity1, Functor2//Arity2, ...))
synchronized([Functor1//Arity1, Functor2//Arity2, ...])

Declares synchronized predicates and synchronized grammar rule non-terminals. 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 declared in the same synchronized directive share the same mutex. In order to use a separate mutex for each predicate (so that they are independently synchronized), a per-predicate synchronized directive must be used.

Synchronized predicates are silently compiled as normal predicates when using back-end Prolog compilers that don't support multi-threading programming. Note that synchronized predicates cannot be declared dynamic (when necessary, declare the predicates updating the dynamic predicates as synchronized).

Declaring a predicate synchronized implicitly makes it deterministic when using a back-end Prolog compiler that supports multi-threading programming. In order to avoid semantic differences in portable code that uses synchronized predicates across back-end Prolog compilers that may or may not support threads, only deterministic predicates should be declared as synchronized.

This directive must precede any calls to the declared synchronized predicates.

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]).