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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5b86cfa15b273e36 X-Google-Attributes: gid103376,public From: tmoran@bix.com (Tom Moran) Subject: Re: Protected types made of ADT's, and Passive Iterators Date: 1998/09/05 Message-ID: <35f1a607.136859@SantaClara01.news.InterNex.Net>#1/1 X-Deja-AN: 388247133 References: Organization: InterNex Information Services 1-800-595-3333 Newsgroups: comp.lang.ada Date: 1998-09-05T00:00:00+00:00 List-Id: >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.)