From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,63360011f8addace X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-18 19:33:30 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: gnat: time-slicing Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Fri, 19 Jul 2002 02:33:13 GMT References: NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:27243 Date: 2002-07-19T02:33:13+00:00 List-Id: Jan Prazak 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