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,a0f8bfc88538cab5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: task time-out&abort Date: 29 Jun 2005 16:52:21 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1119463703.048124.135330@o13g2000cwo.googlegroups.com> <1119540379.606416.227950@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1120078341 4871 192.74.137.71 (29 Jun 2005 20:52:21 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 29 Jun 2005 20:52:21 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:11740 Date: 2005-06-29T16:52:21-04:00 List-Id: "e.coli" writes: > e.coli ha scritto: > > here the code... > > > i have this simple code... > ------------------------------------ > with Ada.Text_Io; > > procedure Sempliced2 is > > task A_Task is > entry Uno; > end A_Task; > > task body A_Task is > begin > loop > select > accept Uno do > Ada.Text_Io.Put_Line("i do something"); > --here code like > --Horribly_Complicated_Recursive_Function(x,y); > end Uno; > or > terminate; > end select; > end loop; > end A_Task; > > begin --corpo genitore > A_Task.Uno; > end Sempliced2; > ------------------------------------------------ > > Speliced2 call the task entry uno. > now how Speliced2 can terminate the execution of the entry "uno" before > the > end of the call (es. time-out)? You can put the Horribly_Complicated_Recursive_Function inside an ATC: select delay 5.0; then abort Horribly_Complicated_Recursive_Function... end select; And you can pass the time-out as a parameter to the entry call, if you like. But be careful! ATC is a very dangerous feature, which is difficult to get right. And if you get it wrong, you will have nasty timing-dependent bugs. The problem is that any variables modified by Horribly_Complicated_Recursive_Function can be destroyed when it gets aborted by the timeout. The usual way to deal with it is to do most of the work in local data that nobody else looks at. And it can update some more-global thing (like an 'out' parameter of the entry) in an abort-deferred way -- using a protected object, or a pragma Atomic. I think there are some examples in the Ada 95 Rationale. - Bob