comp.lang.ada
 help / color / mirror / Atom feed
From: jcallen@Encore.COM (Jerry Callen)
Subject: Re: Strange behavior by Ada tasks
Date: 27 Mar 90 21:46:46 GMT	[thread overview]
Message-ID: <11444@encore.Encore.COM> (raw)


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)

             reply	other threads:[~1990-03-27 21:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-03-27 21:46 Jerry Callen [this message]
  -- strict thread matches above, loose matches on Subject: below --
1990-03-27 17:57 Strange behavior by Ada tasks Keith Pierce
replies disabled

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