Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.java.programmer Subject: Re: Making one or more threads wait for another to produce a value or fail Followup-To: comp.lang.java.programmer Date: Wed, 01 Jun 2011 12:33:39 +1200 Organization: Geek Central Lines: 72 Message-ID: References: NNTP-Posting-Host: 118-92-86-36.dsl.dyn.ihug.co.nz Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: lust.ihug.co.nz 1306888420 28857 118.92.86.36 (1 Jun 2011 00:33:40 GMT) X-Complaints-To: abuse@ihug.co.nz NNTP-Posting-Date: Wed, 1 Jun 2011 00:33:40 +0000 (UTC) User-Agent: KNode/4.4.11 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4834 In message , Tom Anderson wrote: > Penelope is a widow, or at least her husband isn't around any more (she's > not sure which; long story). There are 108 suitors who would like to marry > her. She hasn't decided which one she'll marry. So, the 108 suitors are > sitting about waiting for her to decide. It's possible that instead of > deciding to marry one of them, she'll deliver some other, exceptional, > verdict (eg "turns out my husband is still alive, and will now murder you > all"). > > Penelope is a thread, as are her suitors. Penelope has plenty to do after > she delivers her verdict, so the verdict is not a return value - it's a > value she'll pass to a method. procedure penelope_and_her_suitors is subtype verdict_string is string(1 .. 12); protected verdict is entry deliver(v : in verdict_string); entry obtain(v : out verdict_string); private v : verdict_string; got_v : boolean := false; end verdict; protected body verdict is entry deliver(v : in verdict_string) when not got_v is begin verdict.v := v; got_v := true; end deliver; entry obtain(v : out verdict_string) when got_v is begin v := verdict.v; end obtain; end verdict; task penelope is end penelope; task type suitor is end suitor; task body penelope is begin --- think about what verdict to deliver verdict.deliver("you all die "); -- or whatever end penelope; task body suitor is the_verdict : verdict_string; begin verdict.obtain(the_verdict); -- do whatever with it end suitor; suitors : array (1 .. 108) of suitor; begin -- penelope_and_her_suitors null; -- wait for all the fun to finish end penelope_and_her_suitors;