[comp.lang.ada] Reply to shared variable access . . .

COSTELLO@amstel.llnl.gov (07/03/89)

> Reply to Shared Variables question . . .

--
-- Nicholas,
-- The variable 'Letter' in the Access_Variable task is never being updated.
-- It gets initialized to '*' (at elaboration time - before the Write_Letter_A_
-- To_Variable task starts to run), and remains '*'.  Add the line of code
-- in Access_Variable to continually read from the global 'Unprotected'
-- variable. (Or replace 'PUT_LINE(Letter)' with 'PUT_LINE(Unprotected)')
--
	-- Ed
--


with Text_IO;  use Text_IO;

procedure Unprotected_Shared_Variable is

--
-- This is global to both tasks ...
--
  Unprotected : Character := '*';	
  pragma SHARED(Unprotected);

  task Write_Letter_A_To_Variable;
  task Access_Variable;

  task body Write_Letter_A_To_Variable is
--
-- 'Letter' is local to this task
--
    Letter : constant Character := 'A';	

  begin
    loop
--
-- And is stuck into the GLOBAL variable 'Unprotected'
--
-- This part is correct . . .
--
      Unprotected := Letter;
      delay 0.5;
    end loop;
  end Write_Letter_A_To_Variable;

  task body Access_Variable is
--
-- 'Letter' is local to this task . . .
--  and is initialized at ELABORATION TIME.
-- (That is, it's only written one time, and
-- it gets written before the Write_Letter_A_To_Variable
-- task starts to run, so it will always be '*' ).
--
    Letter : Character := Unprotected;
  begin
    loop
--
-- Insert this line and it will work fine . . .
--
      Letter := Unprotected;
      Put (Letter);
      delay 3.0;
    end loop;
  end Access_Variable;

begin
  null;
end Unprotected_Shared_Variable;

_________________________________________________________________________
-- Ed Costello
-- Lawrence Livermore National Lab
-- 1-415-422-1012