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,28c043d47104f5d9 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: Controlled types for resource locking Date: 1999/09/08 Message-ID: #1/1 X-Deja-AN: 522688497 References: <936824686.950.0.nnrp-07.c2de848f@news.demon.co.uk> X-Complaints-To: abuse@pacbell.net X-Trace: typhoon-sf.pbi.net 936827022 206.170.2.26 (Wed, 08 Sep 1999 14:43:42 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Wed, 08 Sep 1999 14:43:42 PDT Newsgroups: comp.lang.ada Date: 1999-09-08T00:00:00+00:00 List-Id: >I have some code in which I'm protecting a hardware resource using a >protected type. It's getting quite a mess at the moment with lock/unlocks >all over the place - especially where exception handlers get involved. I'm You can make a controlled type whose Initialize grabs the lock and whose Finalize releases it, then declare an object of this controlled type as the first thing in any subprogram (or block) that needs access to the hardware. Thus you can't execute code inside the subprogram till the Initialize has been called, and you own the resource. Any way you leave the subprogram, you are guaranteed the Finalize will release the resource. p.s. There was a bug in a compiler I used a year or so ago, and which I believe has since been fixed, such that Finalize would be called even if Initialize had failed (raised a Cant_Get_Resource exception, for instance). Make sure nothing like that is happening with your system.