comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Arguments for single-mutex-exclusion on protected types
Date: Sun, 18 Mar 2007 19:50:30 +0100
Date: 2007-03-18T19:50:30+01:00	[thread overview]
Message-ID: <14pgc3ebl0775$.oufva26n9cpv.dlg@40tude.net> (raw)
In-Reply-To: yge7itetqvy.fsf@hugsarin.dmusyd.edu

On Sun, 18 Mar 2007 18:15:13 +0100, Jacob Sparre Andersen wrote:

> Dmitry A. Kazakov wrote:
>> On Fri, 16 Mar 2007 15:29:15 +0100, Jacob Sparre Andersen wrote:
>>> Jeffrey R. Carter wrote:
> 
>>>> The last time I looked at the GNAT sources for protected objects,
>>>> each had a mutex associated with it that was obtained before any
>>>> action, even functions. I guess that hasn't changed.
>>> 
>>> Isn't that the most efficient implementation on a POSIX system?
>>
>> Even if it were, why Ada RTL should care?
> 
> Because my Ada run-time is running on top of a POSIX system.

But Ada RTL could take advantage of knowing what goes on behind POSIX,
which itself is most likely built on top of something else.

>>>  d) Since the protected function bodies can be assumed to be small
>>>     (b), there will be a relatively large overhead in keeping track of
>>>     the number of queued calls to protected functions and procedures.
>>
>> But queue is not the only possible implementation of a waitable object.
>> Protected functions and procedures do not necessarily need queues, they
>> could be implemented using a hierarchical (read-write) mutex. [*] For
>> example, when the processor has an atomic increment instruction, a
>> read-write mutex could be implemented very efficiently. The idea is that
>> you *first* change the read count and then check if there is a potential
>> writer without any locking. If everything is clear, you just continue 2-3
>> instructions later, otherwise you take a system mutex and manage all counts
>> safely.
> 
> Wouldn't we then expect our POSIX system to implement its mutexes
> using this feature?

I don't know. If POSIX were designed with Ada in mind, was it? In
particular, does it have read-write mutexes?

> With SMP systems and multi-core CPU's, I doubt
> that atomic increment instructions are popular among the hardware
> designers (but I may be wrong - this is not my strongest area of
> expertise).

Massively multiple-core systems could take ways quite different from what
we are accustomed now. Forgotten and gone architectures like transputers
could return.

[ Consider a "transaction"-like design of protected objects based on memory
replication (hardware-supported). The protected object state could then be
held in the processor's local memory. Protected function would compare the
change number of its copy and do everything without interlocking if it
hasn't been incremented. ]
 
>>>  e) Since the protected function bodies can be assumed to be small
>>>     (b), the probability of colliding calls to protected functions is
>>>     relatively small.
>>
>> That surely depends on the program logic.
> 
> For "small" = "smaller than the code using the result", it will be
> true up to at least two CPU cores (unless you force the callers to
> synchronise - and then protected objects seem somewhat misplaced - any
> other exceptions).

There are two sufficient parameters:

1. The number of processors which shifts the relation between protected /
unprotected actions code towards protected, if protected implies mutual
exclusion.

2. The number of distinct locks associated with protected objects. This is
especially the issue if you wanted to built it on top of expensive and
limited operating system resources.

> Please remember that the compiler should generate code which is most
> efficient in most cases.  We shouldn't expect it to optimise for a few
> special cases at the cost of the more common cases.

And which relation between protected function/procedure/entry is most
common? I doubt that anybody could have any reliable statistics of.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-03-18 18:50 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-29 11:57 Does Ada tasking profit from multi-core cpus? Gerd
2007-01-29 12:04 ` Georg Bauhaus
2007-01-30 13:55   ` Gerd
2007-02-09 10:18     ` karl
2007-02-09 11:03       ` Stefan Lucks
2007-02-09 11:35         ` Ludovic Brenta
2007-03-04 17:54 `   jpluto
2007-03-05 10:08   ` Ludovic Brenta
2007-03-05 13:12     ` Dmitry A. Kazakov
2007-03-06  5:33       ` tmoran
2007-03-06  8:44         ` Dmitry A. Kazakov
2007-03-07  7:52           ` tmoran
2007-03-07  9:31           ` tmoran
2007-03-06  9:40         ` Colin Paul Gloster
2007-03-06 12:47           ` Jeffrey Creem
2007-03-06 14:44           ` Georg Bauhaus
2007-03-06 16:53         ` Dr. Adrian Wrigley
2007-03-06 18:58           ` tmoran
2007-03-07 10:11             ` Colin Paul Gloster
2007-03-07 18:47               ` tmoran
2007-03-06 18:51         ` Jeffrey R. Carter
2007-03-16 14:29           ` Arguments for single-mutex-exclusion on protected types (Was: Does Ada tasking profit from multi-core cpus?) Jacob Sparre Andersen
2007-03-17  5:26             ` Jeffrey R. Carter
2007-03-17 17:22               ` Robert A Duff
2007-03-17 17:52                 ` Jeffrey R. Carter
2007-03-17 23:06                 ` Randy Brukardt
2007-03-18 17:57                   ` Robert A Duff
2007-03-19 21:49                     ` Randy Brukardt
2007-03-20  0:55                       ` Jeffrey R. Carter
2007-03-20  1:36                         ` Randy Brukardt
2007-03-20 16:32                           ` Jeffrey R. Carter
2007-03-20 17:51                             ` Randy Brukardt
2007-03-21  0:10                               ` Jeffrey R. Carter
2007-03-26 23:38                               ` Robert A Duff
2007-03-26 23:24                           ` Robert A Duff
2007-03-17 10:25             ` Dmitry A. Kazakov
2007-03-18 17:15               ` Arguments for single-mutex-exclusion on protected types Jacob Sparre Andersen
2007-03-18 18:50                 ` Dmitry A. Kazakov [this message]
2007-03-20 12:38                 ` Florian Weimer
2007-03-07  3:58       ` Does Ada tasking profit from multi-core cpus? Steve
2007-03-07  8:39         ` Dmitry A. Kazakov
2007-03-08  5:21           ` Randy Brukardt
2007-03-08 10:15             ` Dmitry A. Kazakov
2007-03-08 21:18               ` accuracy (was: Does Ada tasking profit from multi-core cpus?) Björn Persson
2007-03-09  8:33                 ` accuracy Dmitry A. Kazakov
2007-03-10  1:39                   ` accuracy Randy Brukardt
2007-03-10  9:11                     ` accuracy Dmitry A. Kazakov
2007-03-11  3:03                       ` accuracy Randy Brukardt
2007-03-11  5:21                         ` accuracy tmoran
2007-03-11  8:52                         ` accuracy Dmitry A. Kazakov
2007-03-11 13:57                           ` accuracy Pascal Obry
2007-03-11 14:16                             ` accuracy Dmitry A. Kazakov
2007-03-11 14:37                               ` accuracy Pascal Obry
2007-03-11 15:50                                 ` accuracy Dmitry A. Kazakov
2007-03-11 17:38                                   ` accuracy Pascal Obry
2007-03-11 18:48                                     ` accuracy Dmitry A. Kazakov
2007-03-12 20:20                           ` accuracy Randy Brukardt
2007-03-13  9:33                             ` accuracy Dmitry A. Kazakov
2007-03-10 14:53                     ` accuracy Stephen Leake
2007-03-10 18:36                       ` accuracy Cesar Rabak
2007-03-05 18:46   ` Does Ada tasking profit from multi-core cpus? Jeffrey R. Carter
replies disabled

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