From: juan carlos diaz martin <jdiaz@mx3.redestb.es>
Subject: Gnat Tasking behaviour
Date: 1997/09/08
Date: 1997-09-08T00:00:00+00:00 [thread overview]
Message-ID: <34145385.5D11@mx3.redestb.es> (raw)
[-- Attachment #1: Doc4.txt --]
[-- Type: text/plain, Size: 2826 bytes --]
Hello!!
The following program
1. behaves the same way in GNAT DOS 3.05 and GNAT Win95 3.09
------------
2. behaves different in GNAT DOS 3.07
---------
Main Program:
-------------
--Body
with R;
with S;
procedure Principal is
begin
null;
end Principal;
Package R (increments periodically a variable and prints it):
---------
--Specification
package R is
pragma Elaborate_Body;
end R;
--Body
with D;
with text_io; use text_io;
with Ada.Real_Time; use Ada.Real_Time;
package body R is
N : D.D_T;
task Thread is
pragma Priority( 3);
end Thread;
procedure Codigo_Periodico is
package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
begin
D.Operacion (D.Inc, N);
Put(integer(N));
end Codigo_Periodico;
task body Thread is
T : Time;
Periodo : Time_Span := Milliseconds(2000);
begin
T := Clock + Periodo;
loop
delay until(T);
Codigo_Periodico;
T := T + Periodo;
end loop;
end Thread;
end R;
Package S: (The same than R, but it decrements instead of incrementing)
----------
--Specification
package S is
pragma Elaborate_Body;
end S;
--Body
with D;
with text_io; use text_io;
with Ada.Real_Time; use Ada.Real_Time;
package body S is
N : D.D_T;
task Thread is
pragma Priority(3);
end Thread;
procedure Codigo_Periodico is
package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
begin
D.Operacion (D.Dec, N); --(The only different sentence from package R)
Put(integer(N));
end Codigo_Periodico;
task body Thread is
T : Time;
Periodo : Time_Span := Milliseconds(2000);
begin
T := Clock + Periodo;
loop
delay until(T);
Codigo_Periodico;
T := T + Periodo;
end loop;
end Thread;
end S;
Package D:
---------
--Specification
package D is
type Op_T is (Inc, Dec);
type D_T is new integer;
procedure Operacion (Op : Op_T; Res : out D_T);
end D;
--Body
package body D is
dato : D_T := 0;
procedure Operacion (Op : Op_T; Res : out D_T) is
begin
case Op is
when Inc => dato := dato + 1;
when Dec => dato := dato - 1;
end case;
Res := dato;
end Operacion;
end D;
Well,
The output of GNAT DOS 3.05 and GNAT Win95 3.09 is somthing like that:
0 1 0 1 0 -1 0 1 0 -1 ... (oscilates)
The output of GNAT DOS 3.07 is somthing like that:
0 -1 -2 -3 -4 -5 -6 -7 -8 -9 ... (monotonic)
My Question is:
What is the good one?? Both??
reply other threads:[~1997-09-08 0:00 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