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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Handling transactions? Date: Mon, 27 Jul 2015 19:10:09 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <6b5c318e-430d-4950-9762-e0ecdaa0ac9a@googlegroups.com> <9976ca19-a558-4f4e-80d3-a9b37ee07326@googlegroups.com> <40c8dba8-85e9-42e7-8316-96c976531ab4@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1438042210 26801 24.196.82.226 (28 Jul 2015 00:10:10 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 28 Jul 2015 00:10:10 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:27061 Date: 2015-07-27T19:10:09-05:00 List-Id: "EGarrulo" wrote in message news:40c8dba8-85e9-42e7-8316-96c976531ab4@googlegroups.com... >On Monday, July 27, 2015 at 6:38:37 PM UTC+2, David Botton wrote: >> EGarrulo, your question is not a language question but a design question. >> What you want can be done in any language and depending on what you >> are trying to "roll back" I can think of many many ways to do it. Be >> specific >> and I'm sure some of us can offer advice for your project. >Thank you, but mine is a curiosity. I am new to Ada and I am trying to >understand >how to approach problems the Ada way. My above hypothetical solution >mirrors >what I would have done in C++, by following the RAII (Resource Acquisition >Is >Initialization) idiom. It seems to me that Ada offers a similar idiom with >its controlled types. As always, the best approach depends on exactly what you're doing. In Claw, we needed exclusion locks in some cases, and we found the best pattern for them was to use a limited controlled type: type Lock is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (Object : in out Lock); overriding procedure Finalize (Object : in out Lock); The body of Initialize seizes the lock, and the body of Finalize frees the lock. Then, the simple act of declaring an object of type Lock gets the lock and holds it until the operation is complete (or fails); the lock is then freed (even if an exception is propagated). This is typically used in a block: declare My_Lock : Lock; -- Gets lock. begin -- Do operations needing the lock. end; -- The lock is freed here, no matter how this block is completed. I suspect that you could use a similar pattern for transactions (although I've never tried it). Randy.