Re: How to make this program more efficient?
On Sep 20, 1:44 am, Jon Harrop <j...@ffconsultancy.com> wrote:
James Kanze wrote:
On Sep 13, 12:28 pm, Jon Harrop <j...@ffconsultancy.com> wrote:
James Kanze wrote:
If there's any thread modifying the object, then all
accesses must be synchronized. Period.
That is incorrect.
Not according to Posix.
Or the Bible, which is also irrelevant.
And not on some of the more recent architectures.
Any major ones?
DEC Alpha, Sun Sparc, and Intel 64 bits, that I know of.
Probably most others as well.
Caches are an obvious counter example where the writer can
write a single word (a pointer to the updated immutable cache)
atomically and readers can read the word atomically safely
without any locking at all.
First, there's formally no guarantee about writing even a single
word.
That is incorrect. There are, of course, already guarantees
such as the one given by .NET as I have already said.
Ensuring that guararantee is going to make programs run almost
an order of magnitude slower.
But that's not the issue; the issue is one of ordering. And
the upcoming C++ standard will be clear here: if more than
one thread accesses the container, and any thread modifies
it, then all accesses must be synchronized.
That is just another serious limitation of the new C++.
That's because it's a limitation of real hardware.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34