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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,319dd710e797e8a2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!koehntopp.de!news.banetele.no!news.eunet.no!kda-news.kongsberg.com!not-for-mail From: "Egil H. H�vik" Newsgroups: comp.lang.ada Subject: Re: Protected type defined in the procedure Date: Wed, 28 Sep 2005 10:53:01 +0200 Organization: News Kongsberg Defence&Aerospace T-Nett Message-ID: References: NNTP-Posting-Host: kda-mfxp-24.kda.kongsberg.com X-Trace: kda-news.kongsberg.com 1127897581 9470 193.71.174.124 (28 Sep 2005 08:53:01 GMT) X-Complaints-To: tommy.fallsen@kongsberg.com NNTP-Posting-Date: Wed, 28 Sep 2005 08:53:01 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Xref: g2news1.google.com comp.lang.ada:5224 Date: 2005-09-28T10:53:01+02:00 List-Id: Will this do: with Ada.Text_IO; procedure protected_type is protected foo is entry wait; procedure release; private continue : boolean := false; end foo; protected body foo is entry wait when continue is begin continue := false; end wait; procedure release is begin continue := true; end release; end foo; task bar; task body bar is begin loop foo.release; delay 1.0; end loop; end bar; begin loop select foo.wait; Ada.Text_IO.Put_Line("released"); or delay 0.5; Ada.Text_IO.Put_Line("waiting..."); end select; end loop; end protected_type; ~egilhh "Maciej Sobczak" wrote in message news:dhdj5p$o6r$1@sunnews.cern.ch... > Hi, > > While learning Ada I have found the following problem. > It is possible to define a task within some procedure, like here: > > procedure Hello is > > task SomeTask is > -- ... some entries > end SomeTask; > > task body SomeTask is > begin > -- ... (2) > end SomeTask; > > begin > -- ... (1) > end Hello; > > At some point I decided to use a protected object to act as a shared > data between (1) and (2). I was unable to find any way to define > appropriate protected type within the Hello procedure. Separate package > helped with this, but the question remains: is it at all possible to > define a protected type (*all* of it, including implementation of its > procedures, functions and entries) within the procedure where it is > supposed to be used? I find it to be reasonable, especially when > compared with the possibility of defining the whole task this way. In > fact, the protected object is not going to be used outside of the > Hello+SomeTask combo, so there is no need to pollute the project with > separate packages just for things like this. > > > -- > Maciej Sobczak : http://www.msobczak.com/ > Programming : http://www.msobczak.com/prog/