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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6009c73a58f787a0,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-11 05:48:18 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada Subject: How to avoid unreferenced objects (mutexes etc) Date: Fri, 11 Jan 2002 13:48:15 GMT Message-ID: <3c3ee8c8.105408250@News.CIS.DFN.DE> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1010756895 28892433 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:18773 Date: 2002-01-11T13:48:15+00:00 List-Id: Hi all! I have a question. Let I implement mutex and locking objects as follows: protected type Mutex is entry Seize; procedure Release; private Owned : Boolean := False; end Mutex; type Lock (Resource : access Mutex) is new Ada.Finalization.Limited_Controlled with null record; procedure Initialize (Object : in out Lock) is begin Object.Resource.Seize; end Initialize; procedure Finalize (Object : in out Lock) is begin Object.Resource.Release; end Finalize; The idea is to write critical sections as follows: Temp : Lock (Mutex_of_a_resource'Access); begin ... -- Safe access to the resource end; -- Mutex is released even if an exception propagates The problem is that the object Temp is never referenced. The compiler complains of that, but it is a minor problem. The questions are 1. Has the compiler right to optimize out Temp? 2. Is there a better solution? Thanks, Dmitry Kazakov