comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: can someone help me with this code (explanation)
Date: Thu, 25 Sep 2014 20:11:19 +0300
Date: 2014-09-25T20:11:19+03:00	[thread overview]
Message-ID: <c8j0lhFl112U1@mid.individual.net> (raw)
In-Reply-To: <6e1f86e6-c17a-428e-bb19-460c5ba26c8a@googlegroups.com>

On 14-09-25 18:54 , Stribor40 wrote:
> Why would this one even be possible....

It is possible in principle, because of promises that are absent from
the Ada language standard, but quite unlikely in practice, in any real
Ada implementation. (However, in more complex programs, with less clear
task timing, similar things can be more likely even in practice.)

> Bill
> Bill
> Bill
> John
> John 
> 
> If say Bill starts first...as soon as he enters John will be in queue....

John may not yet be in the queue, for two reasons, the first one
possibly true in practice:

- First reason: If your computer has only one core processor, and this
core can run only one task at a time (common in the past, less common
now), the core may run Gourmet first, until she enters the accept
statement, then run Bill until he calls Make_A_Hot_Dog, then run Gourmet
again up to the delay statement, giving John no chance to execute and
reach his call of Make_A_Hot_Dog. This can happen in practice. However,
in practice, when Gourmet executes the delay statement the core will
start running John until he calls Make_A_Hot_Dog and enters the queue.

- Second reason: In principle, the Ada language standard makes no
promises about task execution speed. John may take as long as he pleases
to reach his first Make_A_Hot_Dog call - John can be so slow that Bill
gets and eats all his hot dogs before John orders his first one. This is
very unlikely in this example program, but such things can happen in
practice in larger programs if there are other tasks with a priority
higher than John's priority, but lower than the priorities of Bill and
Gourmet.

By the way, using Ada.Text_IO from multiple tasks without
synchronisation, on the same file (Standard_Output), is not to be
recommended -- such use of Ada.Text_IO is not "task safe", I believe.
However, Put_Line and similar simple things usually work with GNAT
Text_IO from multiple tasks.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


  reply	other threads:[~2014-09-25 17:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-25 13:44 can someone help me with this code (explanation) Stribor40
2014-09-25 14:56 ` Björn Lundin
2014-09-25 15:01   ` Björn Lundin
2014-09-25 15:54   ` Stribor40
2014-09-25 17:11     ` Niklas Holsti [this message]
2014-09-25 19:41       ` Stribor40
2014-09-25 19:53         ` Jeffrey Carter
2014-09-25 20:10         ` Niklas Holsti
2014-09-25 22:27           ` Jeffrey Carter
2014-09-26  7:04             ` Björn Lundin
2014-09-26  7:58               ` J-P. Rosen
2014-09-26 10:24                 ` G.B.
2014-09-26 11:48                 ` Björn Lundin
2014-09-26 12:49                   ` J-P. Rosen
2014-09-26 14:15                     ` Björn Lundin
2014-09-26 14:49                       ` J-P. Rosen
2014-09-26 15:31                         ` Björn Lundin
2014-09-26 16:08                           ` G.B.
2014-09-30  4:22                             ` Brad Moore
2014-09-30 21:59                               ` Georg Bauhaus
2014-10-01 15:38                                 ` Brad Moore
2014-09-26 16:23                           ` Dmitry A. Kazakov
2014-09-26 20:38                           ` J-P. Rosen
2014-09-27 18:16                             ` Björn Lundin
2014-09-26 16:43                       ` Niklas Holsti
2014-09-26 16:45                 ` Niklas Holsti
2014-10-09  2:45                   ` Randy Brukardt
2014-09-26 16:44             ` Niklas Holsti
2014-09-26  5:06           ` J-P. Rosen
2014-09-25 16:53 ` 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