From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Ravenscar vs selective wait Date: Tue, 24 Mar 2015 00:25:55 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Tue, 24 Mar 2015 07:25:07 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="3f77efd256cd7097938236a53a6861ee"; logging-data="22321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Z7FVM35FE6s46ZsicNuXuQDdYRyEYV/w=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: Cancel-Lock: sha1:NLvaSufsyJbt8QSQdSs453JkKro= Xref: news.eternal-september.org comp.lang.ada:25230 Date: 2015-03-24T00:25:55-07:00 List-Id: On 03/23/2015 11:48 PM, Simon Wright wrote: > Simon Wright writes: > >> Is it possible to construct an analog of the selective wait using the >> Ravenscar profile? >> >> Turn_On_The_Lamp; >> Next := Clock + Milliseconds (500); >> select >> accept Reset do >> Next := Clock + Milliseconds (500); >> end Reset; >> or >> delay until Next; >> Turn_Off_The_Lamp; >> end select; > > This is rather simplified from what I want to achieve, and I can think > of an ugly solution for it. > > Turn_On_The_Lamp; > Next := Clock + Milliseconds (500); -- Next is a shared variable > loop > delay until Next; > if Next <= Clock then > exit; > else > -- something else in the program has updated Next > end if; > end loop; > Turn_Off_The_Lamp; > > But what if I need the next wake-up to be *earlier*? Seems to me you could do what you originally asked about with 3 tasks and a PO: Lamp task: Turn_On; Next := Clock + Interval; PO.Set_Expiration (Expiration_Time => Next); loop PO.Wait (Result => Wait_Result); case Wait_Result is when Reset => Next := Clock + Interval; PO.Set_Expiration (Expiration_Time => Next); when Timeout => Turn_Off; exit; end case; end loop; PO: procedure Set_Expiration (Expiration_Time : in Time); procedure Delay_Expired; procedure Reset_Expiration; function Expiration return Time; entry Wait (Result : out Wait_Result_ID); The delay task would poll function Expiration and compare it to Clock, calling Delay_Expired when Expiration >= Clock. Some 3rd task would call Reset_Expiration when the expiration should be extended. With some more complication this could also allow resetting to an earlier time. -- Jeff Carter "What's the amount of the insult?" Never Give a Sucker an Even Break 104