comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: Safety of unprotected concurrent operations on constant objects
Date: Tue, 13 May 2014 09:01:44 -0600
Date: 2014-05-13T09:01:44-06:00	[thread overview]
Message-ID: <qtqcv.27961$hv6.6727@fx17.iad> (raw)
In-Reply-To: <fw1hrdv0jufx$.fetdmr8mer8o$.dlg@40tude.net>

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.


  reply	other threads:[~2014-05-13 15:01 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-02  8:42 Safety of unprotected concurrent operations on constant objects Natasha Kerensikova
2014-05-03 13:43 ` sbelmont700
2014-05-03 20:54   ` Natasha Kerensikova
2014-05-03 21:40     ` Simon Wright
2014-05-04  0:28       ` Jeffrey Carter
2014-05-04  7:46         ` Natasha Kerensikova
2014-05-04  8:06           ` Dmitry A. Kazakov
2014-05-04 15:18           ` sbelmont700
2014-05-04 15:57             ` Natasha Kerensikova
2014-05-04 18:30               ` sbelmont700
2014-05-04 19:34                 ` Dmitry A. Kazakov
2014-05-05 19:04               ` Brad Moore
2014-05-05 21:23                 ` Brad Moore
2014-05-04 21:44                   ` Shark8
2014-05-05  8:39                     ` Simon Wright
2014-05-05 15:11                       ` Brad Moore
2014-05-05 16:36                         ` Dmitry A. Kazakov
2014-05-06  6:00                           ` Brad Moore
2014-05-06  8:11                             ` Dmitry A. Kazakov
2014-05-06  8:48                               ` Alejandro R. Mosteo
2014-05-06  9:49                                 ` G.B.
2014-05-06 12:19                                   ` Dmitry A. Kazakov
2014-05-06 12:58                                     ` G.B.
2014-05-06 15:00                                       ` Dmitry A. Kazakov
2014-05-06 16:24                                         ` G.B.
2014-05-06 19:14                                           ` Dmitry A. Kazakov
2014-05-07  6:49                                             ` Georg Bauhaus
2014-05-07  7:40                                               ` Dmitry A. Kazakov
2014-05-07 11:25                                                 ` G.B.
2014-05-07 12:14                                                   ` Dmitry A. Kazakov
2014-05-07 13:45                                                     ` G.B.
2014-05-07 14:08                                                       ` Dmitry A. Kazakov
2014-05-07 17:45                                                   ` Simon Wright
2014-05-07 18:28                                                     ` Georg Bauhaus
2014-05-07  4:59                                         ` J-P. Rosen
2014-05-07  7:30                                           ` Dmitry A. Kazakov
2014-05-07  8:26                                             ` J-P. Rosen
2014-05-07  9:09                                               ` Dmitry A. Kazakov
2014-05-07 11:29                                                 ` J-P. Rosen
2014-05-07 12:36                                                   ` Safety of unprotected concurrent operations on constant objects (was: Safety of unprotected concurrent operations on constant objects) Dmitry A. Kazakov
2014-05-07 14:04                               ` Safety of unprotected concurrent operations on constant objects G.B.
2014-05-08  4:12                               ` Brad Moore
2014-05-08  8:20                                 ` Dmitry A. Kazakov
2014-05-08 10:30                                   ` G.B.
2014-05-09 13:14                                   ` Brad Moore
2014-05-09 19:00                                     ` Dmitry A. Kazakov
2014-05-10 12:30                                       ` Brad Moore
2014-05-10 20:27                                         ` Dmitry A. Kazakov
2014-05-11  6:56                                           ` Brad Moore
2014-05-11 18:01                                           ` Brad Moore
2014-05-12  8:13                                             ` Dmitry A. Kazakov
2014-05-13  4:50                                               ` Brad Moore
2014-05-13  8:56                                                 ` Dmitry A. Kazakov
2014-05-13 15:01                                                   ` Brad Moore [this message]
2014-05-13 15:38                                                     ` Brad Moore
2014-05-13 16:46                                                       ` Simon Wright
2014-05-13 19:15                                                         ` Dmitry A. Kazakov
2014-05-13 16:08                                                     ` Dmitry A. Kazakov
2014-05-13 20:27                                                       ` Randy Brukardt
2014-05-14  4:30                                                         ` Shark8
2014-05-14 21:37                                                           ` Randy Brukardt
2014-05-14 21:56                                                             ` Robert A Duff
2014-05-15  1:21                                                               ` Shark8
2014-05-14 14:30                                                         ` Brad Moore
2014-05-15  8:03                                                         ` Dmitry A. Kazakov
2014-05-15 13:21                                                           ` Robert A Duff
2014-05-15 14:27                                                             ` Dmitry A. Kazakov
2014-05-15 15:53                                                               ` Robert A Duff
2014-05-15 16:30                                                                 ` Dmitry A. Kazakov
2014-10-26 17:11                                                                   ` Jacob Sparre Andersen
2014-05-08 19:52                                 ` Randy Brukardt
2014-05-06 16:22                             ` Robert A Duff
2014-05-06 19:07                               ` Dmitry A. Kazakov
2014-05-08  5:03                                 ` Brad Moore
2014-05-08 12:03                                   ` Brad Moore
2014-05-08 19:57                                     ` Randy Brukardt
2014-05-09  2:58                                       ` Brad Moore
2014-05-05 20:29                         ` Natasha Kerensikova
2014-05-08  3:41                           ` Randy Brukardt
2014-05-08  9:07                             ` Natasha Kerensikova
2014-05-08 19:35                               ` Randy Brukardt
2014-05-08  3:12                       ` Randy Brukardt
2014-05-05 22:30                     ` Brad Moore
2014-05-04 16:04             ` Peter Chapin
2014-05-04 18:07               ` Natasha Kerensikova
2014-05-04 18:55           ` Jeffrey Carter
2014-05-04 19:36             ` Simon Wright
2014-05-04 20:29               ` Jeffrey Carter
2014-05-05 22:46             ` Brad Moore
2014-05-04 20:25           ` Shark8
2014-05-04 23:33             ` sbelmont700
2014-05-05  7:38             ` Dmitry A. Kazakov
2014-05-08  3:45               ` Randy Brukardt
2014-05-08  3:19 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox