comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com (Tom Moran)
Subject: Re: Protected types made of ADT's, and Passive Iterators
Date: 1998/09/05
Date: 1998-09-05T00:00:00+00:00	[thread overview]
Message-ID: <35f1a607.136859@SantaClara01.news.InterNex.Net> (raw)
In-Reply-To: m3btou4urs.fsf@mheaney.ni.net

>procedure Modify_Items (Collection : in out Collection_Type) is
>...
>begin
>   Seize (Collection.Guard);
> do stuff
> Release(Collection.Guard);
>end Modify_Items;
  A way to lessen the chance of missing/excess Seize/Release is to
make a controlled type
  type Ptr_To_Collection_Type is access all Collection_Type;
  type Check_Busy_Type(P : Ptr_To_Collection_Type) is new
Ada.Finalization.Controlled with null record;.
  Inside any routine that needs to have serialized access to a
Collection_Type, put a declaration, eg
procedure Modify_Items (Collection : in out Collection_Type) is
  Grab : Check_Busy_Type(access Collection);
...
begin
  Then the Initialize of Check_Busy_Type will be certainly be called
and can do the Seize, and the Finalize can do the release.  It just
requires one line of code (the "Grab" declaration) added to existing
routines and does not depend on the programmer remembering to Seize
and Release at the right places.  (I simplify, but just slightly.)






  reply	other threads:[~1998-09-05  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-04  0:00 Protected types made of ADT's, and Passive Iterators John Woodruff
1998-09-05  0:00 ` Matthew Heaney
1998-09-05  0:00   ` Tom Moran [this message]
1998-09-07  0:00   ` Mats Weber
1998-09-17  0:00     ` Matthew Heaney
1998-09-05  0:00 ` Tom Moran
1998-09-07  0:00 ` Mats Weber
replies disabled

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