comp.lang.ada
 help / color / mirror / Atom feed
* Re: visibility of protected objects
  2001-12-03  5:04 visibility of protected objects Tony Gair
@ 2001-12-03  3:42 ` Jeffrey Carter
  2001-12-03 17:40 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Jeffrey Carter @ 2001-12-03  3:42 UTC (permalink / raw)


Tony Gair wrote:
> 
> Does anyone how to use a protected task for inter task communication and if
> so can they tell me..........

What is a protected task?

If you mean a protected object, you have a single protected object and
multiple tasks that call its operations..

If that doesn't answer your question, then you have a different question
and need to ask it.

-- 
Jeff Carter
"Your mother was a hamster and your father smelt of elderberries."
Monty Python & the Holy Grail



^ permalink raw reply	[flat|nested] 3+ messages in thread

* visibility of protected objects
@ 2001-12-03  5:04 Tony Gair
  2001-12-03  3:42 ` Jeffrey Carter
  2001-12-03 17:40 ` Matthew Heaney
  0 siblings, 2 replies; 3+ messages in thread
From: Tony Gair @ 2001-12-03  5:04 UTC (permalink / raw)



Does anyone how to use a protected task for inter task communication and if
so can they tell me..........





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: visibility of protected objects
  2001-12-03  5:04 visibility of protected objects Tony Gair
  2001-12-03  3:42 ` Jeffrey Carter
@ 2001-12-03 17:40 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 2001-12-03 17:40 UTC (permalink / raw)



"Tony Gair" <tonygair@donot.spam.btinternet.com> wrote in message
news:9ue5hp$ipc$1@plutonium.btinternet.com...
>
> Does anyone how to use a protected task for inter task communication and
if
> so can they tell me..........

The example below uses a protected object to exchange a string between a
producer (who reads it from standard input) and a consumer (who writes it to
standard output).

--STX
with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Test_ITC is

   protected Shared is
      entry Put (S : in String);
      entry Get (S : out Unbounded_String);
   private
      Have_S : Boolean := False;
      S : Unbounded_String;
   end;

   protected body Shared is

      entry Put (S : in String) when not Have_S is
      begin
         Shared.S := To_Unbounded_String (S);
         Have_S := True;
      end;

      entry Get (S : out Unbounded_String) when Have_S is
      begin
         S := Shared.S;
         Have_S := False;
      end;

   end Shared;

   protected Text_IO_Lock is
      entry Seize;
      procedure Release;
   private
      In_Use : Boolean := False;
   end;

   protected body Text_IO_Lock is

      entry Seize when not In_Use is
      begin
         In_Use := True;
      end;

      procedure Release is
      begin
         In_Use := False;
      end;

   end Text_IO_Lock;

   task Consumer;

   task body Consumer is
      S : Unbounded_String;
   begin
      loop
         Shared.Get (S);

         Text_IO_Lock.Seize;
         Ada.Text_IO.Put ("consumer got string '");
         Ada.Text_IO.Put (To_String (S));
         Ada.Text_IO.Put_Line ("'");
         Text_IO_Lock.Release;

         exit when Length (S) = 0;
      end loop;
   end Consumer;

   Line : String (1 .. 81);
   Last : Natural;

begin

   loop
      Text_IO_Lock.Seize;
      Ada.Text_IO.Put ("ready: ");
      Text_IO_Lock.Release;

      Ada.Text_IO.Get_Line (Line, Last);

      Text_IO_Lock.Seize;
      Ada.Text_IO.Put_Line ("producing string");
      Text_IO_Lock.Release;

      Shared.Put (Line (1 .. Last));

      exit when Last = 0;
   end loop;

end Test_ITC;







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-12-03 17:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-03  5:04 visibility of protected objects Tony Gair
2001-12-03  3:42 ` Jeffrey Carter
2001-12-03 17:40 ` Matthew Heaney

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