comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: "C - like: THIS" pointer to a task type inside a task function
Date: Mon, 23 Jan 2012 22:17:00 +0000 (UTC)
Date: 2012-01-23T22:17:00+00:00	[thread overview]
Message-ID: <jfkm8s$li5$1@speranza.aioe.org> (raw)
In-Reply-To: 19cglxkm60u91.1ezey0dra41do$.dlg@40tude.net

> An entry can have in, out, in-out parameters like a subprogram call. You
> can pass parameters in and get the results out, just in one call.

  If the client task, after giving work to the server, needs to do things
other than wait for a result, then adding an "out" parameter won't work.

> It is considered bad design when two components know each other. Usually
> the software is designed in a way that component relationships are
> asymmetric, e.g. the callee knows nothing about the caller. Component knows
> nothing about the container, etc. The advantage of this approach is its
> robustness. You can have as many callers you need without changing the
> callee.

  True, but if the server really does need to call the client, it will
need to know the "name" of the client.  You can do this with
Ada.Task_Identification:

with Ada.Task_Identification;
procedure Testti is

  task type Clients is
    entry Get_Result(Result  : in     Character);
  end Clients;

  task Server is
    entry Get_Work(Work    : in     Character);
  end Server;

  task body Clients is
    Generated_Result: Character;
  begin
    for Jobs in 1 .. 5 loop -- we do want eventual termination of this demo!
      -- generate some work todo, then
      Server.Get_Work(Work => 'w');
      -- do other stuff, then ask for the results
      select
        accept Get_Result(Result  : in     Character) do
          Generated_Result := Result;
        end Get_Result;
        -- use Generated_Result
      or
        terminate; -- Server is dead!  Don't just hang around.  Die.
      end select;
    end loop;
  end Clients;

  Client_List: array (1 .. 10) of Clients;

  task body Server is
    use type Ada.Task_Identification.Task_Id;
    Todo    : Character;
    Result  : Character;
    Source  : Ada.Task_Identification.Task_Id;
  begin
    loop
      select
        accept Get_Work(Work    : in     Character) do
          Todo := Work;
          Source := Get_Work'Caller;
        end Get_Work;
      or
        terminate;
      end select;
      -- handle Todo, generating Result, then pass it back to Source client.
      for I in Client_List'range loop
        if Client_List(I)'Identity = Source then
          Client_List(I).Get_Result(Result);
          exit;
        end if;
        -- if a task other than one in Client_List gave us work, toss it.
      end loop;
    end loop;
  end Server;

begin
  null;  -- Client_List and Server tasks are working away...
end Testti;



  reply	other threads:[~2012-01-23 22:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-23 19:32 "C - like: THIS" pointer to a task type inside a task function Ada BRL
2012-01-23 19:59 ` Dmitry A. Kazakov
2012-01-23 22:17   ` tmoran [this message]
2012-01-24  8:47     ` Dmitry A. Kazakov
2012-01-24 17:12   ` Ada BRL
2012-01-24 18:43     ` Dmitry A. Kazakov
2012-01-25 12:43       ` Ada BRL
2012-01-25 13:48         ` Dmitry A. Kazakov
2012-01-25 15:05           ` Ada BRL
2012-01-25 18:10             ` Dmitry A. Kazakov
2012-01-26 15:19               ` Ada BRL
2012-01-26  4:17           ` Randy Brukardt
2012-01-24 17:27   ` Ada BRL
2012-01-23 20:20 ` Jeffrey Carter
2012-01-24 17:13   ` Ada BRL
2012-01-24  6:39 ` J-P. Rosen
2012-01-25  0:42 ` Adam Beneschan
2012-01-25  0:46   ` Adam Beneschan
2012-01-25  7:38   ` J-P. Rosen
replies disabled

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