Logtalk reference manual
Built-in predicate: threaded_race/1

threaded_race/1

Description

threaded_race((Goal; Goals))

Allows a disjunction of goals to be interpreted as a set of competing goals, each one running on its own thread. This call always succeeds. When one of the goals succeeds, the other ones are aborted (i.e. their threads are terminated). The result (of the first goal to succeed) is sent back to the thread of the object containing the call (this). The corresponding threaded_exit/1 goal must match all the goals in the disjunction. This is useful when you have a set of different methods to solve a problem without knowing a priori which one will lead to the fastest result.

Template and modes

threaded_race(+callable)

Errors

One of the goals is a variable:
instantiation_error
One of the goals is neither a variable nor a callable term:
type_error(callable, Goal)

Examples

Prove a set of competing goals asynchronously, each one in its own thread:
threaded_race((Goal; Goals)
Prove a set of competing messages to self asynchronously, each one in its own thread:
threaded_race(::(Message; Messages))
Prove a set of competing messages to an object asynchronously, each one in its own thread:
threaded_race((Object::(Message; Messages))