comp.lang.ada
 help / color / mirror / Atom feed
* Newbie: Code isn't executed
@ 2005-08-04 14:10 Thomas Ruschival
  2005-08-04 14:47 ` Ed Falis
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Thomas Ruschival @ 2005-08-04 14:10 UTC (permalink / raw)


Hello Ada group
I am a student learning Ada at university. I played with some tasks
that want to join another task for a rendevouz, its a modiefied exaple
from the lectures. Basically I let 2 tasks sleep a different amount of
time then wake up and execute a piece of code with another task during
a rendevouz, I count the number how often a task got executed.
Somehow a piece of code never gets executed - neither me nor nor my
tutor has a clue why -- here is the code:

Thanks for _ANY_ comments - I know this isn't the best way of coding -
but it was just meant as an example until strange things happened

Thomas


with Ada.Text_IO;
use Ada.Text_IO;

procedure myfirst
is
   type Name is (Peter,Michael);
   type Statistics is array(Name) of Integer;
   Partner : Name;
   Stat : Statistics :=(others => 0);
   Total: Positive :=1000;

   task Michael_task;
   task Peter_task;
   task Susan is
      entry Dinner;
   end Susan;


   task body Peter_task
   is
   begin
      while Total > 0 loop
         Put("Peters turn");
         New_Line;
         Partner := Peter;
         Susan.Dinner;
         delay 0.002;
      end loop;
   end Peter_task;

   task body Michael_task is
   begin
      while Total > 0 loop
         Put("Michaels turn");
         New_Line;
         Partner := Michael;
         Susan.Dinner;
         delay 0.001;
      end loop;
   end Michael_task;


   task body Susan
   is
   begin

      while Total > 0 loop
         Put("susans turn");
         New_Line;
         accept Dinner do
            stat(Partner) := stat(Partner)+1;
            Put("Susan is having dinner with...."& Name'Image(Partner));
            New_Line;
         end Dinner;
         Total := Total-1;
      end loop;

-- THIS WILL NEVER BE EXECUTED --- WHY ??????????????????????
      Put("Statistics:");
      New_Line;
      Put("---------------------------------------------");
      New_Line;
      Put("Peter:  "&Integer'Image(Stat(Peter)));
      New_Line;
      Put("Michael:  "&Integer'Image(Stat(Michael)));
      New_Line;
      Put("---------------------------------------------");
      New_Line;

   end Susan;


begin -- Procedure
   null;
end myfirst;



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

end of thread, other threads:[~2005-08-06  5:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-04 14:10 Newbie: Code isn't executed Thomas Ruschival
2005-08-04 14:47 ` Ed Falis
2005-08-04 14:48 ` Egil Høvik
2005-08-04 15:07 ` Martin Dowie
2005-08-04 17:37   ` tmoran
2005-08-04 20:57     ` Randy Brukardt
2005-08-05  6:11       ` Vinzent 'Gadget' Hoefler
2005-08-06  3:52         ` tmoran
2005-08-04 20:20   ` Simon Wright
2005-08-04 15:09 ` Martin Dowie
2005-08-04 16:37 ` SOLVED: " Thomas Ruschival
2005-08-05  2:43 ` Steve
2005-08-06  5:33   ` Jeffrey Carter

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