comp.lang.ada
 help / color / mirror / Atom feed
* Tasking and C-interfaces - variable storage
@ 1994-11-03 19:47 mcnett michael david
  1994-11-05  3:17 ` R. William Beckwith
  0 siblings, 1 reply; 2+ messages in thread
From: mcnett michael david @ 1994-11-03 19:47 UTC (permalink / raw)



I am having a problem concerning tasking. I am using GNAT-1.83 for Sparc 4.1.

It appears that when I instantiate a task, the variables that are directly 
defined in the task body are correctly being maintained (ie. a seperate copy
for each task instantiated).  However, I am making calls to several C routines
within each task, but it appears that each task is not maintaining its own
copies of the variables in those C routines.

Here are parts of the code with my understanding of the tasks at the
end of the code:


--*************************************************************************
--Driver
with Gen_Disk;
procedure Model is
  -- variables defined
begin
  -- set-up statements

   declare
      package HP_DISK is new GEN_DISK(Num_of_Disks);
      Disk_Array : array (1 .. Num_of_Disks) of HP_DISK.Handle;

   begin
      for i in 1 .. Num_of_Disks loop

         HP_DISK.create(Disk_Array(i));
         disk := i;
         busID := i;
         busOwner := BUS_FREE;
         results := HP_DISK.Disk_Init(Disk_Array(i),
                                      disk,
                                      busId,
                                      busOwner'address);

   end loop; -- Disk Initializations


   while NOT End_of_File (My_File) loop
	-- read in parameters from file

      HP_DISK.Disk_Transfer(Disk_Array(Integer(disk)),
                            other parm's);
      endtime := (HP_DISK.Elapsed(Disk_Array(Integer(disk))));

   end loop;

end Model;





package body Gen_Disk is
   task body Disk is
      package C_Procedure is new C_Procs;

   -- Ada variables defined here

   Start_Time  : C_Lib2.Time_T := C_Procedure.Gettime; -- for each disk
   Stop_Time   : C_Lib2.Time_T := C_Procedure.Gettime; -- for each disk
	                                                -- for each disk
   Initialized : Integer := 0;

   begin
      loop
         select
            when Initialized = 0 =>        -- only initialize each disk once
               accept Disk_Init (Disk         : in C_Lib2.C_Int;
                                 Busid        : in C_Lib2.C_Int;
                                 Busowner     : System.Address) do
	         -- initializes a disk through a c routine
               end Disk_Init;


         or
            when Initialized > 0 =>
               accept Disk_Transfer (foo...) do
                  Start_Time := C_Procedure.Gettime;
                  C_Procedure.Diskdevicetransfer(parms);
               end Disk_Transfer;

	-- other select statements -> one of which assigns a value to 
	--       stop_time through C_Procedure.Gettime call

         or terminate;
         end select;

      end loop;
   end Disk;




   procedure Create (A_Handle :out Handle) is
      My_Handle : Handle := new Disk;

   begin
      A_Handle := My_Handle;
   end Create;



   function Disk_Init (A_Disk : Handle;
                       --other parm's) return Integer is
   begin
      A_Disk.Disk_Init(Disk, Busid, Busowner);
      return 1;
   end Disk_Init;



   procedure Disk_Transfer(A_Disk : Handle;
                           --other parm's ) is
   begin
      A_Disk.Disk_Transfer(Disk, Sector, Nsectors, Write, Buffer);
   end Disk_Transfer;

	-- other procedures

end Gen_Disk;

--*************************************************************************
-- Sorry about including so much actual code.  I didn't know how to get
-- my point across without showing all of this.
--*************************************************************************




 Start_Time and Stop_Time are only set through a C_Procedure.Gettime
 call.  This call is made for each disk.

 The actual C routine GetTime simply checks a structure which stores
   a simulation time clock and returns that value.

 Now, to my understanding, for each disk task created, Start_Time, and
   Stop_Time should be unique for each of these disk tasks.

 When I create the HP_Disks from the Model procedure, the times
   are set correctly (ie. to 0).  When I do the first disk_transfer,
   for the first disk, the start_time is also correct (ie. 0).  The 
   Stop_Time is also correct for the first disk (say value x).

 Now, when the second disk gets to disk_transfer entry, its 
   Start_Time = 0 BEFORE the C_Procedure.Gettime call.  Now I call
   C_Procedure.Gettime thinking it should return 0. But instead,
   it returns x (the value returned to the first disk_transfer 
   Start_Time).

 It appears to me that the values of the second disk_transfer 
   C_Procedure Gettime should still be 0.  Am I wrong?

 So, MY QUESTION is: Does the value of the simulation clock time
   of the actual C routine maintained on a per task basis, or a
   per program basis?


Thanks in advance,

______________________________________________________________
Michael McNett               |
Graduate Student             |
University of Illinois       |
mmcnett@uiuc                 |



















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

end of thread, other threads:[~1994-11-05  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-03 19:47 Tasking and C-interfaces - variable storage mcnett michael david
1994-11-05  3:17 ` R. William Beckwith

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