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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e1c47fd1b76b1c05 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Task entries and access to subprograms. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4253B917.5070800@mailinator.com> Date: Wed, 6 Apr 2005 14:06:23 +0200 Message-ID: <14oz1b2mn4ml7.14949sqgipu8q.dlg@40tude.net> NNTP-Posting-Date: 06 Apr 2005 14:02:00 MEST NNTP-Posting-Host: b10272a0.newsread4.arcor-online.net X-Trace: DXC=o17enW;^6ZC`4<=9bOTW=MN> X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10298 Date: 2005-04-06T14:02:00+02:00 List-Id: On Wed, 06 Apr 2005 12:25:27 +0200, Alex R. Mosteo wrote: > this is a question about the validity of some approach I'm trying. I > know that task entries can't have access parameters. My gnat gap 1.1.0 > linux behaves like that: > > type AInt is access all Integer; > type Code is access procedure; > > task type Blah is > entry One (I : access Integer); -- Illegal and detected. > > entry Two (I : AInt); -- No complaint. Legal? > > entry Three (C : not null access procedure); -- Illegal and detected. > -- I have the Ada0Y features enabled. > > entry Four (C : Code); -- No complaint. > end Blah; > > I want to execute some arbitrary code inside a task. This is because > GtkAda in win32 requires all Gtk calls to be made from the same thread, > and I want to have code outside of that thread able to make Gtk calls > (for abstraction and future extension purposes I don't want to hardcode > all my Gtk calls in that task). > > Apparently the fourth approach works under linux, but I'm worried it may > be a bad trick. If this isn't legal I could use a tagged type with a > defined Execute method, so I'd pass instances of derived types of this > base class to the task, and execute the dispatching call. > > I'm interested in your oppinion about the second and fourth entries > above, They are fully legal. > and in other alternatives to the tagged type workaround. Tagged is also OK: type Code is abstract tagged ...; procedure Execute (This : in out Code) is abstract; task type Blah is entry Do_It (X : in out Code'Class); end Blah; Note also that tagged object has one big advantage over an access-to-procedure object. You can pass the parameters for the action to be executed within the object using additional object's members for that purpose. --------- If tasks are permanently assigned to the same code you can use either generics or access attribute: task type Blah (What_To_Do : access Code['Class]) is entry Do_It; end Blah; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de