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!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx10.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Termination of tasks waiting on a protected queue References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1400454359 68.145.219.148 (Sun, 18 May 2014 23:05:59 UTC) NNTP-Posting-Date: Sun, 18 May 2014 23:05:59 UTC Date: Sun, 18 May 2014 17:05:59 -0600 X-Received-Bytes: 3846 X-Received-Body-CRC: 2861102348 Xref: news.eternal-september.org comp.lang.ada:19892 Date: 2014-05-18T17:05:59-06:00 List-Id: On 14-05-18 01:32 AM, Natasha Kerensikova wrote: > The problem is, how to terminate cleanly the worker tasks in a > non-Ravenscar environment when the main application is completed? > > From my understanding of ARM 9.3, I need a terminate alternative in the > worker tasks. But those can only exist in selective accepts, so I have > to turn things around and make the task wait for one of its entries to > be called, rather than wait for an external protected entry. > > But then, how can a worker task entry be used to solve my problem? A > protected operation cannot call a task entry, because it's potentially > blocking. The job generator cannot call the entry directly, because it > would block when the task is not ready, so I still need a queue between > the generator and the worker task. A protected entry can however requeue to a task entry. I was faced with a similar problem in the non-Ravenscar task pools in Paraffin. I did not want the programmer to have to call some protected subprogram to trigger the task pool to terminate. I also did not want to have to wait for a timeout to expire before the application could exit. I wanted it to be immediate. So in your example, it might look something like; package body Example is function Create_Job return Job_Description is Result : Job_Description; begin return Result; end Create_Job; procedure Enqueue_Job (Job : in Job_Description) is begin Queue.Append (Job); end Enqueue_Job; protected body Queue is entry Append (Job : in Job_Description) when True is begin if not Idle then requeue Worker.Work_Queued; else List.Append (Job); end if; end Append; procedure Get_Next (Job : out Job_Description) is begin Job := List.First_Element; List.Delete_First; end Get_Next; function Is_Empty return Boolean is begin return List.Is_Empty; end Is_Empty; procedure Worker_Idle is begin Idle := True; end Worker_Idle; function Worker_Is_Idle return Boolean is begin return Idle; end Worker_Is_Idle; end Queue; task body Worker is Job : Job_Description; begin loop begin Queue.Worker_Idle; if not Queue.Is_Empty then Queue.Get_Next (Job); else select accept Work_Queued (Next_Job : Job_Description) do Job := Next_Job; end Work_Queued; or terminate; end select; end if; -- end; end loop; end Worker; end Example; Brad > Thanks in advance for your help, > Natasha >