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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!u6g2000prc.googlegroups.com!not-for-mail From: Bender Newsgroups: comp.lang.ada Subject: Re: Running a background task Date: Thu, 15 May 2008 17:49:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9n4Xj.111458$TT4.6745@attbi_s22> NNTP-Posting-Host: 76.25.96.235 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1210898978 20612 127.0.0.1 (16 May 2008 00:49:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 May 2008 00:49:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u6g2000prc.googlegroups.com; posting-host=76.25.96.235; posting-account=znprRwoAAABc0sBerLGAFs7TqvGvhALp User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:88 Date: 2008-05-15T17:49:38-07:00 List-Id: On May 15, 6:16 pm, "Jeffrey R. Carter" wrote: > 1. You're missing the terminator semicolon. Ignore that. Just remnants of me hastily retyping my code in here. It all compiles fine. > 2. It's generally not a good idea to reuse the identifier "String", since it > hides the predefined type String, which will cause confusing error msgs if you > ever try to use that type. Got it. > You have no need for the access type. You can simply say > > Status_Task : Poll_For_Status; > > Status_Task won't do anything, since it waits for a call to On_String. > > You can simplify this even more by saying > > task Status_Task is > entry On_String (...); > end Status_Task; > > This assumes that Status_Task is the only instance of Poll_For_Status. I believe I originally did it this way, but then changed to using the access stuff because it wasn't behaving the way I wanted it to. I thought using the new operator would hold the key to Handle_Msg not caring about whether the task had finished yet or not, but it didn't. > This infinite loop is inside the accept for On_String, which means the task that > calls On_String will be blocked indefinitely. That's my question in a nutshell. I need the task to run forever. I need the Handle_Msg procedure to end and start handling other incoming messages. > 1. Having the task store the value passed to it: > > Side : Sideab; > begin -- Poll_For_Status; > accept On_String (String : in Sideab) do > Side := String; > end On_String; > > loop > ... Will this solve my problem? Unfortunately I'm at home at the moment, but once I get into work I'll give it a shot. Once the 'end On_String' is reached, will Handle_Msg continue on, while the task continues to run? > 2. Communicating via a protected object rather than a rendezvous. This is a > bigger change, but depending on your needs might result in a better design. This is such a simple task that I think what's above should be simple enough to handle it, but I'll read up on it if necessary. > It may not be important to you, but your loop does not execute every 3 seconds. > There may be some time after the delay expires before the task starts executing > again, and using "delay" allows those times to accumulate; there's also the time > to call the subprogram. If you want it to be as close to every 3 seconds as you > can get, you should use the "delay until" statement. Yeah, I had read something about this before. I'll look into it. Thanks for all your help.