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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3abdc4d72c0b7e9d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!h1g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Running a background task Date: Thu, 15 May 2008 15:31:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <760f4092-577e-440e-9fef-fb3ff3389560@h1g2000prh.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1210890702 18907 127.0.0.1 (15 May 2008 22:31:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 May 2008 22:31:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h1g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:84 Date: 2008-05-15T15:31:42-07:00 List-Id: On May 15, 1:51 pm, Bender wrote: > Hi, I'm pretty new to Ada, and need to figure out a way to kick off a > background task that runs more or less forever, while normal execution > of the program continues. > > Thus far I've figured out how to create a task and start it, but the > procedure calling it requires the task to finish before continuing > on. I'm sure I just must be using the wrong mechanisms, but I can't > really figure out the answer. When Handle_Msg calls on the On_String entry, this starts a rendezvous, and Handle_Msg stops when the rendezvous is done. Since the "accept" has a "do" part, the rendezvous will not be done until the "do" completes, which in your case never happens. Thus, Handle_Msg will never proceed past the entry call. It's hard for me to give a solution, since I don't know just what you're trying to accomplish; but you may want to move the loop out of the "accept". -- Adam > Task definition > --------------------- > (spec) > task type Poll_For_Status is > entry On_String (String : in SideAB) > end Poll_For_Status; > > type Task_Access is access Poll_For_Status; > Status_Task : Task_Access; > > (body) > task body Poll_For_Status is > begin > accept On_String (String : in SideAB) do > loop > delay 3.0 > Send_Status_Req (String); > end loop; > end On_String; > end Poll_For_Status; > > Calling procedure > ------------------------ > procedure Handle_Msg(...) is > String : SideAB; > ... > begin > ... > Status_Task := new Poll_For_Status > Status_Task.On_String (String); > ... > > If I remove the loop in the task body, it works fine. Putting it in > seems to halt execution. > > Am I missing anything?