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: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx17.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Safety of unprotected concurrent operations on constant objects References: <6c2cd5d4-a44c-4c18-81a3-a0e87d25cd9e@googlegroups.com> <83ha6vuynrzs.1jk08faxb8mnl.dlg@40tude.net> <1jebi7cf92ak4.1trmstj8qi3wm.dlg@40tude.net> <1i6pyg077xlrv.vnwotzzgb0ut$.dlg@40tude.net> <10pk27v48vhcb$.1qkf6roq2yzjn$.dlg@40tude.net> <1qq0ryc8c4l2m.1driqwwiwwl02.dlg@40tude.net> <%vhcv.255737$s87.168969@fx11.iad> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1399993302 68.145.219.148 (Tue, 13 May 2014 15:01:42 UTC) NNTP-Posting-Date: Tue, 13 May 2014 15:01:42 UTC Date: Tue, 13 May 2014 09:01:44 -0600 X-Received-Bytes: 4596 X-Received-Body-CRC: 1787155813 X-Original-Bytes: 4838 Xref: number.nntp.dca.giganews.com comp.lang.ada:186382 Date: 2014-05-13T09:01:44-06:00 List-Id: On 14-05-13 02:56 AM, Dmitry A. Kazakov wrote: > On Mon, 12 May 2014 22:50:03 -0600, Brad Moore wrote: > >> I lumped task safe programs with while loops into the >> Potentially_Blocking category, because while loops can be used to >> implement busy spin-loops, which can be considered a form of blocking. > > Loops are used in many (if not most) lock-free algorithms. They have > bounded time, because the loop condition is that the task has been > preempted during execution of the loop body, which may happen only once, > provided scheduling is any reasonable. > >>> What I had in mind are designs like: >>> >>> type T is record >>> M : aliased Mutex; >>> ... >>> end record; >>> >>> A safe operation on this type looks like: >>> >>> procedure Safe_Search (X : in out T; ...) is >>> Lock : Holder (T.M'Access); >>> begin >>> Unsafe_Search (X, ...); >>> end Safe_Search; >>> >>> Here safe operations call to unsafe ones all the time and never do each >>> other because M is not reeentrant. >> >> Thanks for the example. A good case to consider. By the rules I'm >> thinking of, this would not be a task-safe construct however, which I >> think is rightly so. >> >> The Task_Safe attribute is about subprograms that can be proven to be >> safe. This construct is unsafe, because it doesn't guarantee that there >> aren't direct concurrent calls to Unsafe_Search happening while inside >> the body of Safe_Search. (It would probably be too difficult to prove, >> and so its better to assume the worst, when it comes to safety.) >> Therefore Safe_Search is also not a task-safe call. > > This is why I consider these attributes useless as they would work for > marginal cases only. I think most of the code out there that was written for concurrency would probably satisfy the rules. (i.e. It doesn't seem marginal to me) In the case of your example, it likely could be made to satisfy the rules with some simple adjustments. For example, you could fold the body of Unsafe_Search into the body of Safe_Search. Then you would be guaranteeing that there would be no way to circumvent the lock, as there is only the one entry point to your function. Your mutex lock function could then have the Task_Safe aspect. Another approach would be to put the body of Unsafe_Search inside a protected object, again guaranteeing that there is no way to circumvent the protection. I think most protected objects typically do not call unsafe subprograms. > > [...] > > The rules you are proposing seem to me focusing on rather atomicity than > task safety. > The goal is to be able to say that a subprogram can be called safely, without erroneousness with other concurrent calls. Atomicity plays a part of it, but subprograms such as pure functions that don't modify state also fall under the umbrella.