comp.lang.ada
 help / color / mirror / Atom feed
From: john schneider <j-schneider@ti.com>
Subject: Re: Tasking newbee
Date: 1997/04/01
Date: 1997-04-01T00:00:00+00:00	[thread overview]
Message-ID: <33415AA9.41C67EA6@ti.com> (raw)
In-Reply-To: 33412898.2A8C@INnet.be


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.




  reply	other threads:[~1997-04-01  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-01  0:00 Tasking newbee Sebastien Pochic
1997-04-01  0:00 ` john schneider [this message]
1997-04-01  0:00 ` Richard Toy
1997-04-05  0:00 ` elaine.waybright
replies disabled

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