comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Task entries and access to subprograms.
Date: Wed, 6 Apr 2005 14:06:23 +0200
Date: 2005-04-06T14:02:00+02:00	[thread overview]
Message-ID: <14oz1b2mn4ml7.14949sqgipu8q.dlg@40tude.net> (raw)
In-Reply-To: 4253B917.5070800@mailinator.com

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



  parent reply	other threads:[~2005-04-06 12:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-06 10:25 Task entries and access to subprograms Alex R. Mosteo
2005-04-06 10:54 ` Adrien Plisson
2005-04-06 12:06 ` Dmitry A. Kazakov [this message]
2005-04-06 12:22   ` Alex R. Mosteo
2005-04-07  2:05 ` Jeffrey Carter
2005-04-07  7:23   ` Alex R. Mosteo
2005-04-07 14:01     ` Robert A Duff
2005-04-07 23:23     ` Randy Brukardt
2005-04-08  6:49       ` Alex R. Mosteo
2005-04-08 14:49         ` Robert A Duff
2005-04-08 15:23           ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox