2006-12-28 13:03:34 +00:00
<?xml version="1.0" encoding="utf-8"?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" >
< head >
< meta http-equiv = "content-type" content = "application/xml+xhtml; charset=utf-8" / >
< title > Logtalk built-in predicate: threaded_race/1< / title >
< link rel = "stylesheet" href = "../../screen.css" type = "text/css" media = "screen" / >
< link rel = "stylesheet" href = "../../print.css" type = "text/css" media = "print" / >
< / head >
< body >
< div class = "top-left" > Logtalk reference manual< / div >
< div class = "top-right" > Built-in predicate: threaded_race/1< / div >
< div class = "bottom-left" > < span class = "page" / > < / div >
< div class = "bottom-right" > < span class = "page" / > < / div >
< div class = "navtop" > < a href = "../../index.html" > contents< / a > > < a href = "../index.html" > reference manual< / a > > < a href = "../index.html#builtins" > built-in predicates< / a > < / div >
< h2 class = "codenp" > threaded_race/1< span id = "builtins_threaded_race1" / > < / h2 >
< h4 > Description< / h4 >
< pre > threaded_race((Goal; Goals))< / pre >
< p >
2007-02-19 18:58:28 +00:00
Allows a disjunction of goals to be interpreted as a set of < em > competing< / em > 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 (< em > this< / em > ). The corresponding < code > threaded_exit/1< / code > goal < strong > must< / strong > 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.
2006-12-28 13:03:34 +00:00
< / p >
< h4 > Template and modes< / h4 >
< pre > threaded_race(+callable)< / pre >
< h4 > Errors< / h4 >
< dl >
< dt > One of the goals is a variable:< / dt >
< dd > < code > instantiation_error< / code > < / dd >
< dt > One of the goals is neither a variable nor a callable term:< / dt >
< dd > < code > type_error(callable, Goal)< / code > < / dd >
< / dl >
< h4 > Examples< / h4 >
< dl >
2007-02-19 18:58:28 +00:00
< dt > Prove a set of competing goals asynchronously, each one in its own thread:< / dt >
2006-12-28 13:03:34 +00:00
< dd > < code > threaded_race((Goal; Goals)< / code > < / dd >
2007-02-19 18:58:28 +00:00
< dt > Prove a set of competing messages to < em > self< / em > asynchronously, each one in its own thread:< / dt >
2006-12-28 13:03:34 +00:00
< dd > < code > threaded_race(::(Message; Messages))< / code > < / dd >
2007-02-19 18:58:28 +00:00
< dt > Prove a set of competing messages to an object asynchronously, each one in its own thread:< / dt >
2006-12-28 13:03:34 +00:00
< dd > < code > threaded_race((Object::(Message; Messages))< / code > < / dd >
< / dl >
< div class = "footer" >
< div class = "copyright" >
< span > Copyright © < a href = "mailto:pmoura@logtalk.org" > Paulo Moura< / a > — < a href = "http://logtalk.org" > Logtalk.org< / a > < / span > < br / >
2007-02-19 18:58:28 +00:00
< span > Last updated on: February 13, 2007< / span >
2006-12-28 13:03:34 +00:00
< / div >
< div class = "navbottom" >
< span > < a href = "threaded_ignore1.html" > previous< / a > | < a href = "../../glossary.html" > glossary< / a > | < a href = "threaded_exit1.html" > next< / a > < / span > < br / >
< span > < a href = "http://validator.w3.org/check/referer" > XHTML< / a > + < a href = "http://jigsaw.w3.org/css-validator/check/referer" > CSS< / a > < / span >
< / div >
< / div >
< / body >
< / html >