comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: gnat: time-slicing
Date: Fri, 19 Jul 2002 02:33:13 GMT
Date: 2002-07-19T02:33:13+00:00	[thread overview]
Message-ID: <wccd6tkla52.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: pan.2002.07.15.10.24.43.431977.7868@gmx.net

Jan Prazak <janp9@gmx.net> writes:

> Hello,
> 
> I have seen this example program in a tutorial:
> 
> ------------
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Task_Demo is
>   task A;
>   task body A is
>   begin
>     Put_Line("b");
>     Put_Line("b");
>   end A;
> begin
>   Put_Line("a");
>   Put_Line("a");
> end Task_Demo;
> ---------------

The above example is erroneous, which means that the output is totally
unpredictable.  The reason it's erroneous is that two tasks are messing
with the same shared variable (the standard output file) at the same
time.  There's been a lot of confusing discussion about what a file is,
and whether this is a "device" or a "file" and so forth.  You're correct
in thinking that writing to standard output writes to the screen (by
default).  But that's all irrelevant.  The point is, you have two tasks
messing with the same variable (in this case, what Ada calls an
"internal file"), and that's wrong.

Note that "erroneous" is an Ada technical term.  It doesn't mean exactly
the same thing as it does in plain English (unfortunately).  Look it up
in the RM, if you like.

> The output is:
> a
> a
> b
> b
> 
> But I want the output to be:
> 
> ab
> 
> ab

It doesn't matter what you *want* -- this program could do *anything*,
since it's erroneous.  As Robert Dewar pointed out, it could erase your
entire hard disk.  Or, as the C folks like to put it, it might make
demons fly from your nose.

There's no standard Ada way to make this program do anything in
particular, because it is erroneous (i.e. unpredictable).

> (the tutorial says that this is the output with enabled time-slicing)

I haven't seen this tutorial.  Perhaps its point is that you can get
different outputs from erroneous programs, depending on compiler
switches.  Perhaps the author means that it is *possible* to get the
above output when time slicing is turned on (and perhaps some experiment
showed that to be true).  True, but there is certainly no way to
guarantee that output (in standard Ada).

I suspect the tutorial is confusing.  You shouldn't be trying to get
things to behave in a certain way by fiddling with compiler switches.
You should be writing code that obeys the rules (unlike the above
example), and therefore gives the results you want.

> I have tried to use -gnatT100, and -gnatT1, and pragma
> Time_Slice(0.000001) etc., but none of this works.
> I have gnat for Linux.
> 
> Jan

- Bob



  parent reply	other threads:[~2002-07-19  2:33 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 11:25 gnat: time-slicing Jan Prazak
2002-07-15  8:44 ` Dale Stanbrough
2002-07-15 19:10   ` Jan Prazak
2002-07-15 17:16     ` David C. Hoos
2002-07-15 23:30       ` Jan Prazak
2002-07-16  0:54         ` Jan Prazak
2002-07-16 10:46         ` Lutz Donnerhacke
2002-07-16 11:57           ` Aaro Koskinen
2002-07-16 12:57           ` SteveD
2002-07-16 15:18           ` Florian Weimer
2002-07-16 13:29     ` Marin David Condic
2002-07-17 19:29       ` Jan Prazak
2002-07-15 13:07 ` time-slicing David C. Hoos
2002-07-15 14:56   ` time-slicing Ian Broster
2002-07-15 19:10   ` time-slicing Jan Prazak
2002-07-15 19:10   ` time-slicing Jan Prazak
2002-07-15 19:05     ` time-slicing Anders Gidenstam
2002-07-15 23:30       ` time-slicing Jan Prazak
2002-07-15 20:33         ` time-slicing Darren New
2002-07-16 16:30         ` time-slicing Pascal Obry
2002-07-16 23:05           ` time-slicing Jan Prazak
2002-07-16 21:33     ` time-slicing Robert Dewar
2002-07-15 21:03 ` gnat: time-slicing tmoran
2002-07-16 13:04   ` Jan Prazak
2002-07-16 21:29 ` Robert Dewar
2002-07-17 19:29   ` Jan Prazak
2002-07-17 16:44     ` Pascal Obry
2002-07-17 21:38       ` Jan Prazak
2002-07-17 19:21         ` Randy Brukardt
2002-07-17 22:44           ` Jan Prazak
2002-07-17 19:57             ` Marin David Condic
2002-07-18 18:38               ` Larry Kilgallen
2002-07-20 11:52                 ` Robert Dewar
2002-07-17 19:43         ` Pascal Obry
2002-07-18 18:55           ` Jan Prazak
2002-07-18 17:01             ` Pascal Obry
2002-07-18 17:03             ` Pascal Obry
2002-07-18 22:38         ` chris.danx
2002-07-18  2:50     ` R. Tim Coslet
2002-07-18 12:54       ` SteveD
2002-07-20 11:56       ` Robert Dewar
2002-07-18 12:02     ` Frank J. Lhota
2002-07-19  2:33 ` Robert A Duff [this message]
2002-07-19 13:32   ` Jan Prazak
2002-07-19 23:46   ` Keith Thompson
2002-07-20  0:36     ` Robert A Duff
2002-07-20  4:25       ` Darren New
2002-07-20 11:47     ` Robert Dewar
2002-07-21 10:58       ` Keith Thompson
2002-07-31 22:28       ` Robert A Duff
2002-08-01 19:28   ` Erroneous execution? (was Re: gnat: time-slicing) Ben Brosgol
2002-08-01 22:03     ` Robert A Duff
2002-08-02  3:59       ` Ben Brosgol
2002-08-13 22:30         ` Robert A Duff
2002-08-02  4:17       ` Robert Dewar
2002-07-19  3:17 ` time-slicing SteveD
2002-07-19 13:32   ` time-slicing Jan Prazak
2002-07-19 12:41     ` time-slicing SteveD
  -- strict thread matches above, loose matches on Subject: below --
2002-07-18  4:44 gnat: time-slicing Grein, Christoph
2002-07-18 18:55 ` Jan Prazak
2002-07-18 16:35   ` Sergey Koshcheyev
2002-07-19  1:37   ` Robert A Duff
replies disabled

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