comp.lang.ada
 help / color / mirror / Atom feed
From: COSTELLO@amstel.llnl.gov
Subject: Reply to shared variable access . . .
Date: 3 Jul 89 15:34:00 GMT	[thread overview]
Message-ID: <8907031527.AA15125@ajpo.sei.cmu.edu> (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

                 reply	other threads:[~1989-07-03 15:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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