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: 28 Mar 2008 10:51:19 +0100
Date: 2008-03-28T10:51:19+01:00 [thread overview]
Message-ID: <wvbrhceryy5k.fsf@astra06.norway.sun.com> (raw)
In-Reply-To: 87prtfzrtl.fsf@mid.deneb.enyo.de
>>>>> "FW" == Florian Weimer <fw@deneb.enyo.de> writes:
FW> * Ole-Hjalmar Kristensen:
>> If you mean that it may be difficult to optimize, I agree, but I
>> cannot agree that you need *more* than an entryless protected object
>> to implement a hash table, since it guarantees that each operation on
>> the object is indivisible.
FW> You need some kind of signaling construct. Suppose you put some access
FW> value as a value into the hash table. If there's no signaling (the case
FW> of an entryless protected object, it seems), a task that retrieves the
FW> value from the table cannot make any assumptions regarding the object
FW> the access value refers to, unless there is some other form of
FW> synchronization.
First, I never said it can be used to synchronize something which is
outside the protected object or the hash table. But it will serialize
the access to the protected object, so any task will see consistent
key, value pairs, which is all the synchronization you need for the
hash table itself.
Second, I cannot find anything in the RM which says you can make *any*
assumptions about objects which are outside the protected object so I
cannot see how signaling will help you.
Actually there are two cases here:
1. The task is calling a protected function or procedure to retrieve
the pointer and accesses the object through the pointer after the
call. This is obviously bad code unless the object is atomic, which
in practice means a single word.
2. The task is calling a protected function or procedure and accesses
the object through the pointer while it is inside the protected
object. In both cases you are guaranteed that you will see any
previous updates to the protected object itself and that no one is
updating the protected object while you are inside, but unless the
other object is atomic I do not think you have the guarantee that
you even see previous updates to it, at least in the multiprocessor
case. You may speculate that since the implementation of a
protected call typically involves a memory barrier, it will be safe
to access data outside the protected object, but I would not bet on
it.
>> On the other hand, I cannot see any reason why Annex C just couldn't
>> say that intrinsic subprograms for compare-amd-swap and similar
>> machine operations shall be provided *if* they are available on a
>> platform.
FW> CAS alone is not sufficient, you also need some sort of barrier (both
FW> against compiler optimizations and reordering in the silicon).
Which is why I said compare-and-swap and similar machine operations.
With respect to compiler optimizations, I assume you are thinking of
the kind of reordering decribed by Boehm in his paper where some
compilers introduced extra reads and writes while the pthread mutex
was not held? This is obviously a problem, the compiler needs to know
whether a variable may be accessed by multiple threads or not to do
sensible optimizations. But I assume that pragma atomic would be
sufficient to take care of such cases (all atomic objects are volatile):
"15 For an atomic object (including an atomic component) all reads and
updates of the object as a whole are indivisible.
16 For a volatile object all reads and updates of the object as a whole are
performed directly to memory.
16.a Implementation Note: This precludes any use of register
temporaries, caches, and other similar optimizations for that object."
When it comes to reordering in the silicon, at least in the Solaris
case, this is already taken care of in the atomic library operations,
see under NOTES in the excerpt from the man page below. Only if you
need synchronization between *different* variables do you need memory
barriers.
Standard C Library Functions atomic_ops(3C)
NAME
atomic_ops - atomic operations
SYNOPSIS
#include <atomic.h>
DESCRIPTION
This collection of functions provides atomic memory opera-
tions. There are 8 different classes of atomic operations:
atomic_add(3C) These functions provide an atomic addition
of a signed value to a variable.
atomic_and(3C) These functions provide an atomic logical
'and' of a value to a variable.
atomic_bits(3C) These functions provide atomic bit setting
and clearing within a variable.
atomic_cas(3C) These functions provide an atomic comparison
of a value with a variable. If the com-
parison is equal, then swap in a new value
for the variable, returning the old value of
the variable in either case.
atomic_dec(3C) These functions provide an atomic decrement
on a variable.
atomic_inc(3C) These functions provide an atomic increment
on a variable.
atomic_or(3C) These functions provide an atomic logical
'or' of a value to a variable.
atomic_swap(3C) These functions provide an atomic swap of a
value with a variable, returning the old
value of the variable.
<snip>
NOTES
Atomic instructions ensure global visibility of atomically-
modified variables on completion. In a relaxed store order
system, this does not guarantee that the visibility of other
variables will be synchronized with the completion of the
atomic instruction. If such synchronization is required,
memory barrier instructions must be used. See
membar_ops(3C).
--
C++: The power, elegance and simplicity of a hand grenade.
next prev parent reply other threads:[~2008-03-28 9:51 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 [this message]
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
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