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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.155.194 with SMTP id vy2mr8243453pab.19.1409949629446; Fri, 05 Sep 2014 13:40:29 -0700 (PDT) X-Received: by 10.140.30.201 with SMTP id d67mr69888qgd.8.1409949629172; Fri, 05 Sep 2014 13:40:29 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!r2no15146907igi.0!news-out.google.com!i10ni2qaf.0!nntp.google.com!m5no6121918qaj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 5 Sep 2014 13:40:29 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.240.227.47; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 87.240.227.47 References: <6967b17b-acb9-4b44-b21a-6ddcab1e1065@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2c395fc3-344c-45b3-9fd2-94819d6c0f26@googlegroups.com> Subject: Re: Strange behavior From: Laurent Injection-Date: Fri, 05 Sep 2014 20:40:29 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:188884 Date: 2014-09-05T13:40:29-07:00 List-Id: Am Freitag, 5. September 2014 22:34:17 UTC+2 schrieb Robert A Duff: > Laurent writes: >=20 >=20 >=20 > > with Ada.Text_IO; >=20 > > procedure Two_Cooperating_Tasks is >=20 > > =20 >=20 > > task type Simple_Task (Message : Character; How_Many : Positive); >=20 > > =20 >=20 > > task body Simple_Task is >=20 > > =20 >=20 > > begin -- Simple_Task >=20 > > =20 >=20 > > for Count in 1 .. How_Many loop >=20 > > Ada.Text_IO.Put ("Hello from Task " & Message); >=20 > > Ada.Text_IO.New_Line; >=20 > > delay 0.1; >=20 > > end loop; >=20 > > =20 >=20 > > end Simple_Task; >=20 > > =20 >=20 > > Task_A : Simple_Task (Message =3D> 'A', How_Many =3D> 5); >=20 > > Task_B : Simple_Task (Message =3D> 'B', How_Many =3D> 5); >=20 > > =20 >=20 > > begin -- Two_Cooperating_Tasks >=20 > > =20 >=20 > > null; >=20 > > =20 >=20 > > end Two_Cooperating_Tasks; >=20 >=20 >=20 > The above causes erroneous execution, which means that anything can >=20 > happen. Two tasks are writing to standard output without proper >=20 > synchronization. (I would prefer the language defined each output >=20 > call to be atomic, but it doesn't. And that wouldn't help much in your >=20 > example, because you have two calls, Put and New_Line. You could >=20 > combine those into a single Put_Line, by the way.) >=20 >=20 >=20 > If you have only one processor, then the output shown in the text is >=20 > likely to happen. But you can't depend on that. And anyway, nowadays >=20 > you almost certainly have more than one processor, so the tasks are >=20 > executing in parallel. >=20 >=20 >=20 > Synchronization via delay statements is a wrong way to do. >=20 >=20 >=20 > - Bob Yes I understand that. The following examples in the book actually are abou= t this problem and that's the introduction for the protected types. I was j= ust astonished that a so simple program can already behave so unpredictable= . Ok the book was written in 1998 so at this time the result was probably d= ifferent. Thanks to all for the enlightenment Laurent