Logtalk reference manual
Built-in predicate: threaded_race/1

threaded_race/1

Description

threaded_race((Goal; Goals))

Prove a disjunction of goals asynchronously using a new thread. This call always succeeds. The call is equivalent to the competing calls of the individual goals: 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 in a new thread:
threaded_race((Goal; Goals)
Send a set of competing goals as an asynchronous message to self:
threaded_race(::(Message; Messages))
Send a set of competing goals as an asynchronous message to an object:
threaded_race((Object::(Message; Messages))