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=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Strange behavior Date: Fri, 05 Sep 2014 13:23:46 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <6967b17b-acb9-4b44-b21a-6ddcab1e1065@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 5 Sep 2014 20:23:48 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="5b4eadb0ecf28f7f740a0e18f3715b8f"; logging-data="27180"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tu+KHZnOIfh74BgzS9nE0VQnfWMik42s=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 In-Reply-To: <6967b17b-acb9-4b44-b21a-6ddcab1e1065@googlegroups.com> Cancel-Lock: sha1:xDXvFW3pyh7Cm8zshNN8XthBHjY= Xref: number.nntp.dca.giganews.com comp.lang.ada:188882 Date: 2014-09-05T13:23:46-07:00 List-Id: On 09/05/2014 12:30 PM, Laurent wrote: > > begin -- Simple_Task > > for Count in 1 .. How_Many loop > Ada.Text_IO.Put ("Hello from Task " & Message); > Ada.Text_IO.New_Line; > delay 0.1; > end loop; > > end Simple_Task; > > Task_A : Simple_Task (Message => 'A', How_Many => 5); > Task_B : Simple_Task (Message => 'B', How_Many => 5); > > /Volumes/Kingston/GPS/Chapter 17/Build/two_cooperating_tasks > Hello from Task BHello from Task A > > Hello from Task AHello from Task B > > Hello from Task A > Hello from Task B > Hello from Task A > Hello from Task B > Hello from Task AHello from Task B > > [2014-09-05 21:17:14] process terminated successfully, elapsed time: 00.68s > > If the program runs again the result is again different. > > The order of the tasks executing is random and that is ok but why is it changing and why is the New_Line zapped? On most modern computers, 2 tasks can run in parallel, so apparently the system is queuing up high-level requests for output and performing them sequentially. It would not be uncommon, then, for the 2 calls to Put to result in the 2 messages together, followed by the 2 calls to New_line resulting in a blank line. It's surprising that you got so many cases where all the output from one task is followed by all the output from the other. Note that this behavior isn't guaranteed by the language. At a low level, output is done character by character, and nothing requires that the Ada run time or OS queue up requests at a higher level. So it would be perfectly legal to get results such as HellHelo lofr fomr -- Jeff Carter "It's all right, Taggart. Just a man and a horse being hung out there." Blazing Saddles 34