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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news.etla.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Safety of unprotected concurrent operations on constant objects Date: Sun, 4 May 2014 21:34:22 +0200 Organization: cbb software GmbH Message-ID: <6ri4t2dzy5bt.13ew0lqyx8ox2$.dlg@40tude.net> References: <7403d130-8b42-43cd-a0f1-53ba34b46141@googlegroups.com> <6c2cd5d4-a44c-4c18-81a3-a0e87d25cd9e@googlegroups.com> <5e8b7087-5a92-4cd7-957a-c149a381a88b@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: AuYlnUSfTZrfhAkRjyySpQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 2276 Xref: number.nntp.dca.giganews.com comp.lang.ada:186217 Date: 2014-05-04T21:34:22+02:00 List-Id: On Sun, 4 May 2014 11:30:02 -0700 (PDT), sbelmont700@gmail.com wrote: > On Sunday, May 4, 2014 11:57:02 AM UTC-4, Natasha Kerensikova wrote: >> >> How would you "surround it with a mutex"? Do you mean a procedure in a >> >> procted object, or some other scheme I'm not familiar with? > > begin > Semaphore.Lock > Map.Find("Something"); > Semaphore.Unlock; > end Not so. Mutex should always be handled by a controlled "holder" object: declare Lock : Holder (Resource'Access); -- Seize the resource begin Map.Find("Something"); end; -- Release the resource This guaranties that the resource will be released even upon an exception propagation. Regarding containers it is recommended to use reentrant mutexes if operations will be extended or if you fancy re-dispatching. An implementation of reentrant mutex can be found here: http://www.dmitry-kazakov.de/ada/components.htm#Mutexes -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de