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=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.sys.encore:560 comp.lang.ada:3557 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!husc6!encore!jcallen From: jcallen@Encore.COM (Jerry Callen) Newsgroups: comp.sys.encore,comp.lang.ada Subject: Re: Strange behavior by Ada tasks Summary: Strange, but legal Message-ID: <11444@encore.Encore.COM> Date: 27 Mar 90 21:46:46 GMT Reply-To: jcallen@encore.UUCP (Jerry Callen) Followup-To: comp.sys.encore Organization: Encore Computer Corp, Marlboro, MA List-Id: kpierce@umn-d-ub.D.UMN.EDU (Keith Pierce) writes: [Introductory comments regarding use of Ada tasking to implement semaphores and protected variables a la Booch deleted.] >with Semaphore; > >package Nat_Package is > type Protected_Natural is limited private; > procedure Add_One (To_Number : in out Protected_Natural); > procedure Put (The_Number : in Protected_Natural); >private > type Protected_Natural is > record > The_Value : Natural := 0; > Guard : Semaphore.Kind; > end record; >end Nat_Package; [More code and stuff deleted] The problem lies in the fact that Protected_Natural is being passed to Add_One by *copy* and not by *reference*. This is legal (see LRM 6.2, paragraphs 6 through 8), but it means that the two tasks are updating DIFFERENT copies of The_Value (each task has a copy on its own stack). I was able to make your code work by making Protected_Natural an access type that points to the record containing the natural and the task and adding a Create procedure to allocate the record. This causes both tasks to access the same (the only) copy of The_Value. -- Jerry Callen jcallen@encore.com (508) 460-0500 (work)