comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Strange behavior
Date: Fri, 05 Sep 2014 13:23:46 -0700
Date: 2014-09-05T13:23:46-07:00	[thread overview]
Message-ID: <lud64i$qhc$1@dont-email.me> (raw)
In-Reply-To: <6967b17b-acb9-4b44-b21a-6ddcab1e1065@googlegroups.com>

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




  parent reply	other threads:[~2014-09-05 20:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-05 19:30 Strange behavior Laurent
2014-09-05 19:47 ` sbelmont700
2014-09-05 20:05   ` Laurent
2014-09-06  0:53     ` Dennis Lee Bieber
2014-09-06  1:35       ` Adam Beneschan
2014-09-05 20:23 ` Jeffrey Carter [this message]
2014-09-05 20:48   ` Robert A Duff
2014-09-05 20:34 ` Robert A Duff
2014-09-05 20:40   ` Laurent
2014-09-06  1:10     ` Dennis Lee Bieber
replies disabled

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