comp.lang.ada
 help / color / mirror / Atom feed
* Reply to shared variable access . . .
@ 1989-07-03 15:34 COSTELLO
  0 siblings, 0 replies; only message in thread
From: COSTELLO @ 1989-07-03 15:34 UTC (permalink / raw)


> 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1989-07-03 15:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-07-03 15:34 Reply to shared variable access . . COSTELLO

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