* Re: Tasking newbee
1997-04-01 0:00 Tasking newbee Sebastien Pochic
1997-04-01 0:00 ` john schneider
@ 1997-04-01 0:00 ` Richard Toy
1997-04-05 0:00 ` elaine.waybright
2 siblings, 0 replies; 4+ messages in thread
From: Richard Toy @ 1997-04-01 0:00 UTC (permalink / raw)
To: spochic
Sebastien Pochic wrote:
>
> hi,
>
> could someone explain what I should do so that the small tasks (without
> the loop) will end before the "big" task (with the loop), in my example
> it first counts the loop before even beginning the other tasks..
> here's my example:
>
SNIP
Read the LRM more carefully ;-) especially 9.5.2
The behaviour you are experiencing is correct.
--
Regards
Richard Toy
Work: rtoy@dra.hmg.gb
Home: richtoy@pluto.win-uk.net
^ permalink raw reply [flat|nested] 4+ messages in thread
* Tasking newbee
@ 1997-04-01 0:00 Sebastien Pochic
1997-04-01 0:00 ` john schneider
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sebastien Pochic @ 1997-04-01 0:00 UTC (permalink / raw)
hi,
could someone explain what I should do so that the small tasks (without
the loop) will end before the "big" task (with the loop), in my example
it first counts the loop before even beginning the other tasks..
here's my example:
with Ada.Text_IO; use Ada.Text_IO;
procedure Tasking is
task First_Task is
entry Hello;
entry Hi;
end First_Task;
task body First_Task is
begin
loop
select
accept Hello do
for i in 1..1000000 loop
null;
end loop;
put("Hello! I'm task #1");
new_line;
end Hello;
or
accept Hi do
put("Hi, I'm task #1");
new_line;
end Hi;
end select;
end loop;
end First_Task;
task Second_Task is
entry Hello;
entry Hi;
end Second_Task;
task body Second_Task is
begin
loop
select
accept Hello do
put("Hello! I'm task #2");
new_line;
end Hello;
or
accept Hi do
put("Hi, I'm task #2");
new_line;
end Hi;
end select;
end loop;
end Second_Task;
begin
First_Task.Hello;
First_Task.Hi;
Second_Task.Hello;
Second_Task.Hi;
end Tasking;
thanks,
-- sebastien
\/||/
(o o)
-------------oOO--(_)--OOo-------------
Sebastien POCHIC
Computer Science (FSA) - ULB - Brussels
mailto:spochic@INnet.be
----------------------Oooo-------------
oooO ( )
( ) ) /
\ ( (_/
\_)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tasking newbee
1997-04-01 0:00 Tasking newbee Sebastien Pochic
@ 1997-04-01 0:00 ` john schneider
1997-04-01 0:00 ` Richard Toy
1997-04-05 0:00 ` elaine.waybright
2 siblings, 0 replies; 4+ messages in thread
From: john schneider @ 1997-04-01 0:00 UTC (permalink / raw)
Sebastien Pochic wrote:
[snip]
> task body First_Task is
> begin
> loop
> select
> accept Hello do
> for i in 1..1000000 loop
> null;
> end loop;
> put("Hello! I'm task #1");
> new_line;
> end Hello;
> or
> accept Hi do
> put("Hi, I'm task #1");
> new_line;
> end Hi;
> end select;
> end loop;
> end First_Task;
>
[snip]
The structure of entry points REQUIRES just what it is that you
are asking to avoid. Re-read your textbooks/LRM regarding the
behavior of tasks and rendesvous. Any code within the entry
(between do... and ...end) MUST BE completed before either the
caller or "acceptor" can continue, so the loop has to be allowed to
count before your main routine ever gets a chance to make the other
calls.
Try structuring your task(s) like this:
task body First_Task is
begin
loop
select
accept Hello;
for i in 1..1000000 loop
null;
end loop;
put("Hello! I'm task #1");
new_line;
or
accept Hi;
put("Hi, I'm task #1");
new_line;
or -- It's amazing how long a program
terminate; -- can continue to run without this!!
end select;
end loop;
end First_Task;
Of course, this might not accomplish what you want, either, because
all of your tasks are running at the same priority and the rules
don't require the run-time to make any fancy choices between tasks
eligible to run at the same priority. Again -- head for the LRM.
One last warning -- Depending on your compiler, using multiple
tasks to perform serial output to the same file (especially to
the console screen) may have less-than-predictable results.
Now that I've given you more problems than answers ... enjoy
the rest of your day.
John Schneider
j-schneider@ti.com
The opinions are mine, but you are welcome to share them.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tasking newbee
1997-04-01 0:00 Tasking newbee Sebastien Pochic
1997-04-01 0:00 ` john schneider
1997-04-01 0:00 ` Richard Toy
@ 1997-04-05 0:00 ` elaine.waybright
2 siblings, 0 replies; 4+ messages in thread
From: elaine.waybright @ 1997-04-05 0:00 UTC (permalink / raw)
On Tue, 01 Apr 1997 17:24:08 +0200, Sebastien Pochic
<spochic@INnet.be> wrote:
>hi,
>
> could someone explain what I should do so that the small tasks (without
>the loop) will end before the "big" task (with the loop), in my example
>it first counts the loop before even beginning the other tasks..
>here's my example:
>
>
"Extended rendezvous" (accept .. do ... end) should only be used if
the caller and callee have to be synchronized during the entire
rendezvous. Typically, this is the case if the callee protects some
shared resource that the caller wants to access.
In your case, you want the caller to trigger First_Task to start its
computation and then go back to its business of starting the other
task(s). In that case, you should use the simple rendezvous;
accept .. ; for i in .. loop etc. That is, the lengthy computation is
removed from the rendezvous and executed immediately after by the
callee.
Bo Sanden
Professor Bo Sanden
Colorado Technical University
Colorado Springs
Author of Software Systems Construction with Examples in Ada
(Prentice-Hall)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1997-04-05 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-01 0:00 Tasking newbee Sebastien Pochic
1997-04-01 0:00 ` john schneider
1997-04-01 0:00 ` Richard Toy
1997-04-05 0:00 ` elaine.waybright
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox