comp.lang.ada
 help / color / mirror / Atom feed
From: Ole-Hjalmar Kristensen <ole-hjalmar.kristensen@substitute_employer_here.com>
Subject: Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
Date: 15 Apr 2008 14:05:27 +0200
Date: 2008-04-15T14:05:27+02:00	[thread overview]
Message-ID: <wvbrtzi32uig.fsf@astra06.norway.sun.com> (raw)
In-Reply-To: C4195DF6.E2796%yaldnif.w@blueyonder.co.uk

After reading your post about use of suspension objects, I looked in
the RM to see what guarantees we have about the effect of sharing
variables between tasks synchronized with suspension objects. I
completely agree that to work reliably on a multiprocessor the
suspension operations *has* to impose a memory barrier, but I was
unable to find any explicit statement about sharing variables
synchronized with suspension objects.

The sections I have reproduced below is the closest I could get. Since
Suspend_Until_True is potentially blocking, it *could* be signaled (as
defined in 9.10), but I find it strange that it is not mentioned
explicitly. Also, the statement "can be used for two-stage suspend
operations and as a simple building block for implementing
higher-level queues", seems to indicate that the intent indeed is to
be able to use suspension objects to synchronize access to shared
variables. Comments, anyone?

From the AARM:

9.10 Shared Variables

 9.a    Reason:  The underlying principle here is that for one action to
        ``signal'' a second, the second action has to follow a
        potentially blocking operation, whose blocking is dependent on
        the first action in some way.  Protected procedures are not
        potentially blocking, so they can only be "signalers," they
        cannot be signaled.

and 

D.10 Synchronous Task Control

1   [This clause describes a language-defined private semaphore (suspension
object), which can be used for two-stage suspend operations and as a simple
building block for implementing higher-level queues.]
...
9   The procedure Suspend_Until_True blocks the calling task until the state
of the object S is true; at that point the task becomes ready and the state
of the object becomes false.

10   {potentially blocking operation [Suspend_Until_True]} {blocking,
potentially [Suspend_Until_True]} {Program_Error (raised by failure of
run-time check)} Program_Error is raised upon calling Suspend_Until_True if
another task is already waiting on that suspension object.  Suspend_Until_
True is a potentially blocking operation (see 9.5.1).


>>>>> "(b" == (see below) <yaldnif.w@blueyonder.co.uk> writes:

<snip>

    (b> Following on my second post to the point, I was reminded of the package
    (b> Ada.Synchronous_Task_Control, which must also impose memory barriers is it
    (b> is to work reliably on a multiprocessor; so I tried that in my Simpson's
    (b> algorithm test as well. Here is the code:

    >> with Ada.Synchronous_Task_Control;
    >> package body Wait_Free_Atomicity is
    >> 
    >> procedure Sync is
    >> use Ada.Synchronous_Task_Control;
    >> Sema : Suspension_Object;
    >> Bool : Boolean := Current_State(Sema); -- either this
    >> begin
    >> -- Set_True(Sema);                     -- or
    >> -- Suspend_Until_True(Sema);           -- this
    >> end Sync;
    >> 
    >> procedure Update (Atomic_Item : in out an_Atomic; Item : in  an_Item) is
    >> Row : constant a_Bistate := not Atomic_Item.Last_Row_Inspected;
    >> Col : constant a_Bistate := not Atomic_Item.Last_Column_Updated(Row);
    >> begin
    >> Atomic_Item.Data_Slot_Matrix(Row, Col) := Item;
    >> Atomic_Item.Last_Column_Updated(Row) := Col;
    >> Atomic_Item.Last_Row_Updated := Row;
    >> Sync;
    >> end Update;
    >> 
    >> procedure Inspect (Atomic_Item : in out an_Atomic; Item : out an_Item) is
    >> Row : constant a_Bistate := Atomic_Item.Last_Row_Updated;
    >> Col : a_Bistate;
    >> pragma Atomic (Col);
    >> begin
    >> Atomic_Item.Last_Row_Inspected := Row;
    >> Col  := Atomic_Item.Last_Column_Updated(Row);
    >> Item := Atomic_Item.Data_Slot_Matrix(Row, Col);
    >> Sync;
    >> end Inspect;
    >> 
    >> end Wait_Free_Atomicity;

    (b> It works nicely, and is an order of magnitude faster than a protected
    (b> object:

    (b> 20_000_000 updates

    (b> with Suspend_Until_True sync:
    (b> No consistency failures.
    (b>         7.30 real        14.14 user         0.04 sys

    (b> with Current_State sync:
    (b> No consistency failures.
    (b>         3.57 real         6.97 user         0.02 sys

    (b> -- 
    (b> Bill Findlay
    (b> <surname><forename> chez blueyonder.co.uk



-- 
   C++: The power, elegance and simplicity of a hand grenade.



  parent reply	other threads:[~2008-04-15 12:05 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-08  6:04 Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! ME
2008-03-08 22:11 ` Maciej Sobczak
2008-03-09  1:09   ` Christopher Henrich
2008-03-09 13:52     ` Maciej Sobczak
2008-03-09  1:51   ` Phaedrus
2008-03-09  3:17     ` Jeffrey R. Carter
2008-03-09 13:59     ` Maciej Sobczak
2008-03-09  3:15   ` Jeffrey R. Carter
2008-03-09 13:32     ` Maciej Sobczak
2008-03-09 14:02       ` Dmitry A. Kazakov
2008-03-09 18:26       ` Phaedrus
2008-03-10  0:04         ` Ray Blaak
2008-03-10  7:49           ` Georg Bauhaus
2008-03-10 16:48             ` Ray Blaak
2008-03-10  7:53           ` Phaedrus
2008-03-09 22:31       ` Jeffrey R. Carter
2008-03-10  3:53         ` gpriv
2008-03-10  3:04       ` Robert Dewar's great article about the Strengths of Ada over Larry Kilgallen
2008-03-10  9:23         ` Maciej Sobczak
2008-03-10 19:01           ` Jeffrey R. Carter
2008-03-10 22:00             ` Maciej Sobczak
2008-03-11  0:48               ` Jeffrey R. Carter
2008-03-11  7:12                 ` Pascal Obry
2008-03-11  8:59                 ` Maciej Sobczak
2008-03-11  9:49                   ` GNAT bug, Assert_Failure at atree.adb:2893 Ludovic Brenta
2008-03-14 20:03                   ` Robert Dewar's great article about the Strengths of Ada over Ivan Levashew
2008-03-22 21:12           ` Florian Weimer
2008-03-09  8:20   ` Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! Pascal Obry
2008-03-09  9:39     ` Georg Bauhaus
2008-03-09 12:40     ` Vadim Godunko
2008-03-09 13:37       ` Dmitry A. Kazakov
2008-03-09 14:41         ` Vadim Godunko
2008-03-10 20:51           ` Randy Brukardt
2008-03-10 22:30             ` Niklas Holsti
2008-03-10  9:56         ` Ole-Hjalmar Kristensen
2008-03-11 13:58       ` george.priv
2008-03-11 15:41         ` Vadim Godunko
2008-03-12  0:32           ` gpriv
2008-03-12 13:33             ` Maciej Sobczak
2008-03-12 14:41               ` gpriv
2008-03-12 15:22                 ` Vadim Godunko
2008-03-13  0:34                   ` gpriv
2008-03-12 16:28                 ` Maciej Sobczak
2008-03-12 17:24                   ` Samuel Tardieu
2008-03-13  8:41                     ` Maciej Sobczak
2008-03-13 15:20                       ` Samuel Tardieu
2008-03-12 23:54                   ` gpriv
2008-03-13  9:40                     ` Maciej Sobczak
2008-03-13 10:49                       ` Peter C. Chapin
2008-03-13 13:03                         ` Alex R. Mosteo
2008-03-13 14:02                           ` gpriv
2008-03-14  1:12                           ` Randy Brukardt
2008-03-14 10:16                             ` Alex R. Mosteo
2008-03-13 11:42                       ` gpriv
2008-03-13 16:10                         ` Maciej Sobczak
2008-03-13 16:16                           ` gpriv
2008-03-13 22:01                             ` Simon Wright
2008-03-13 22:25                             ` Maciej Sobczak
2008-03-14  2:07                               ` gpriv
2008-03-14  9:29                                 ` Maciej Sobczak
2008-03-14 21:54                                 ` Simon Wright
2008-03-15  2:29                                   ` gpriv
2008-03-15 13:29                                     ` Maciej Sobczak
2008-03-15 16:09                                       ` gpriv
2008-03-11 22:09       ` gpriv
2008-03-09 13:50     ` Maciej Sobczak
2008-03-09 14:54       ` Pascal Obry
2008-03-10 21:24   ` Randy Brukardt
2008-03-11 10:12     ` Alex R. Mosteo
2008-03-22 22:43     ` Florian Weimer
2008-03-26 13:49       ` Ole-Hjalmar Kristensen
2008-03-26 21:27         ` Florian Weimer
2008-03-27  9:31           ` Ole-Hjalmar Kristensen
2008-03-27 23:10             ` Florian Weimer
2008-03-28  9:51               ` Ole-Hjalmar Kristensen
2008-03-28 18:12                 ` Florian Weimer
2008-03-28 21:45                   ` Randy Brukardt
2008-03-31  7:59                   ` Ole-Hjalmar Kristensen
2008-03-31 13:03                     ` (see below)
2008-03-31 14:17                       ` (see below)
2008-04-01  9:02                       ` Ole-Hjalmar Kristensen
2008-04-01 14:12                         ` (see below)
2008-04-02  7:22                           ` Ole-Hjalmar Kristensen
2008-04-02 14:59                             ` (see below)
2008-04-04  6:36                               ` Ole-Hjalmar Kristensen
2008-04-04 13:56                                 ` (see below)
2008-04-04 17:36                                   ` Georg Bauhaus
2008-04-04 17:40                                     ` (see below)
2008-04-15 12:05                               ` Ole-Hjalmar Kristensen [this message]
2008-04-17  4:46                                 ` Randy Brukardt
2008-03-28  6:34             ` Randy Brukardt
2008-04-29  7:15   ` Ivan Levashew
2008-05-01  2:03     ` Steve Whalen
2008-03-14 19:20 ` Mike Silva
2008-03-14 20:43   ` Ed Falis
2008-03-22 22:51 ` Florian Weimer
replies disabled

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