From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Newbie: Code isn't executed
Date: Thu, 4 Aug 2005 19:43:09 -0700
Date: 2005-08-04T19:43:09-07:00 [thread overview]
Message-ID: <w5OdnUIN5IsPTG_fRVn-jA@comcast.com> (raw)
In-Reply-To: 20050804161000.1ffa591b@localhost
"Thomas Ruschival" <Thomas@ruschival.de> wrote in message
news:20050804161000.1ffa591b@localhost...
> 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
>
First:
I recommend you add something like:
EXCEPTION
WHEN Reason: OTHERS =>
Ada.Text_IO.Put( "EXCEPTION NAME: " & Exception_Name( Reason) );
Ada.Text_IO.Put( "EXCEPTION MESSAGE: " & Exception_Message(
Reason) ) );
Ada.Text_IO.Put( "EXCEPTION INFORMATION: " &
Exception_Information( Reason) ) );
To the end of each of task body, at least for experimenting. This helps to
eliminate the problem of tasks dying quietly.
Second:
You may be aware of this, but there are a lot of holes in the program.
It is generally not safe to have 2 tasks manipulating the same global
memory without the use of a protected type. In your example, I think it
would make more sense to pass information to Susan at Dinner:
task Susan is
entry Dinner( Partner : Name );
end Susanl
...
Then instead of:
Partner := Peter;
Susan.Dinner;
use:
Susan.Dinner( Peter );
Also, it is a good idea to avoid doing much inside a rendevous other than
moving data around, so I would suggest changing:
dinnerPartner : Name;
...
accept Dinner( Partner : Name ) do
dinnerPartner := Partner;
end Dinner
stat(dinnerPartner ) := stat(dinnerPartner )+1;
Put("Susan is having dinner with...."& Name'Image(dinnerPartner ));
New_Line;
During the rendevous only one of the threads runs, so I suggest getting it
over as soon as possible.
Steve
(The Duck)
next prev parent reply other threads:[~2005-08-05 2:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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