From: Thomas Ruschival <Thomas@ruschival.de>
Subject: Newbie: Code isn't executed
Date: Thu, 4 Aug 2005 16:10:00 +0200
Date: 2005-08-04T16:10:00+02:00 [thread overview]
Message-ID: <20050804161000.1ffa591b@localhost> (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;
next reply other threads:[~2005-08-04 14:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-04 14:10 Thomas Ruschival [this message]
2005-08-04 14:47 ` Newbie: Code isn't executed 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox