Chapter 7 Examples

 

-- ***************************************************************************
-- *                         First_Task.adb 
-- * Copyright (c) Simon Johnston & Addison Wesley Longman 1996.
-- *
-- * Description: This is a very simple program to create an Ada task.
-- * Inputs:  None.
-- * Outputs: None.
-- ***************************************************************************
with Ada.Text_IO;
procedure First_Task is
   task X;
 
   task body X is
   begin
      loop
         Ada.Text_IO.Put_Line("task X here");
      end loop;
   end X;
begin
   loop
      Ada.Text_IO.Put_Line("First_Task got here");
   end loop;
end First_Task;

 

-- ***************************************************************************
-- *                         Task_Test1.adb 
-- * Copyright (c) Simon Johnston & Addison Wesley Longman 1996.
-- *
-- * Description: This example shows how to use the Ada.Task_Attributes 
-- *    package to add custom data to tasks.
-- * Inputs:  None.
-- * Outputs: None.
-- ***************************************************************************
with Ada.Task_Attributes;
with Ada.Text_IO;
use  Ada;
procedure Task_Test1 is
   package Threaded is new Task_Attributes(Boolean,
					   True);
   task type X is
      entry Start;
   end X;
   task body X is
   begin
      Threaded.Set_Value(False);
      accept Start do
	 null;
      end Start;
   end X;
   An_X : X;
begin
   Text_IO.Put_Line("Current Task = " &
		    Boolean'Image(Threaded.Value));
   Text_IO.Put_Line("An_X Value = " &
		    Boolean'Image(Threaded.Value(An_X'Identity)));
end Task_Test1;

 

-- ***************************************************************************
-- *                         Three_Tasks.adb 
-- * Copyright (c) Simon Johnston & Addison Wesley Longman 1996.
-- *
-- * Description: Shows three concurrent tasks running.
-- * Inputs:  None.
-- * Outputs: None.
-- ***************************************************************************
with Ada.Text_IO;
procedure Three_Tasks is
   task type X(id : Integer);
 
   task body X is
   begin
      loop
         Ada.Text_IO.Put_Line("task" & 
                              Integer'Image(id) & 
                              " here");
      end loop;
   end X;
   Task_1 : X(1);
   Task_2 : X(2);
   Task_3 : X(3);
begin
   loop
      Ada.Text_IO.Put_Line("Three_Tasks got here");
   end loop;
end Three_Tasks;

Contents Page

Copyright © 1996 Simon Johnston &
Addison Wesley Longman