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!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: how to use "in out" for the "self" parameter in a function in a protected object? Date: Mon, 2 Oct 2017 19:08:34 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Tue, 3 Oct 2017 00:08:35 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="20590"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: news.eternal-september.org comp.lang.ada:48299 Date: 2017-10-02T19:08:34-05:00 List-Id: "Jeffrey R. Carter" wrote in message news:oplc73$jqn$1@dont-email.me... > On 09/17/2017 12:40 AM, Frank Buss wrote: >> >> What's the rationale for this behavior and where can I find the >> definition, that it is not allowed? Doesn't look useful to me, because I >> can do this with a procedure. In fact now I have written a procedure with >> an "out" parameter and it works. But it is annoying to declare an extra >> temporary variable for it when I call it. Would be nice, if I could do >> this with a function. > > Modifying the state of a protected object requires exclusive access to it > (a lock of some sort). Simply reading the state does not require a lock, > and multiple reads may proceed in parallel. The definition of POs in 1995 > used protected functions for non-exclusive, read-only access, and > protected procedures and entries for exclusive write access. One can > debate whether this was the best decision, but that's the way POs are > defined. Note that the Ada 2012 Corrigendum added aspect "Exclusive_Functions", which changes the behavior of protected functions to support exclusive read-only access. (This allows a PO to be used as a concurrency wrapper around some non-concurrent data structure without having to change all of the functions of the wrapped data structure into procedures.) Some of us complained about tying read-only access to the use of protected functions long ago, but we got nowhere then and probably wouldn't get anywhere now, either. 98% of the time you can use a protected procedure instead, but there are cases where a procedure isn't possible and you are just stuck. Randy.