[net.lang.ada] Sharing processor between tasks

pearson%bud.DECnet@LLL-ICDC.ARPA ("BUD::PEARSON") (09/24/86)

Somebody in UK-land with an address much too long to work asks why his
program, which defines two free-running tasks that do nothing but print
distinctive messages, prints only one of the two kinds of messages.

The answer is simply that Ada doesn't promise to time-slice tasks of
the same priority. LRM 9.8 says: "For tasks of the same priority, the
scheduling order is not defined by the language." DEC's VAX Ada seems
to follow the strategy of executing one task until it becomes unrunnable
or until a task of higher priority becomes runnable. Makes sense.

  -  Peter
(pearson%anchor.decnet@lll-icdc.arpa)
------

prindle@NADC.ARPA (09/24/86)

Following up on this subject, it should be obvious that, even *if* the run-time
support for a particular compiler *does* time-slice tasks, the program as
given might not work correctly.  If "put(<string>);" were implemented as a
library routine which did a series of "put(<character>);" calls, then it would
be reasonable to expect the output to appear as:

horveirzonttical
alhorizonve........<etc>

The technically correct way to do this kind of thing is to consider the device
being written to as a resource and manage this resource with a third *server*
task.  Only this third task would be allowed to do "put"s to this device, and
would contain an accept for an entry call which passes a string to be written.
Only in this way could it be guaranteed that each string is written without
probability of another string interrupting it.  This is especially important
when using "escape" sequences which cannot be arbitrarily split up.  This
*server* task approach has the desirable (I think, for the original poster)
side effect of perfectly interspersing the strings, since, while one string
is being printed, the task outputting that string is ineligible for execution
and the other task will deposit it's request to output the other string on
the server's entry call queue.  Try it - it really works!

Frank Prindle
Prindle@NADC.arpa