Re: C++ Threads, what's the status quo?
Zeljko Vrba wrote:
On 2007-01-14, JohnQ <johnqREMOVETHISprogrammer@yahoo.com> wrote:
OK, so you're presenting it as strictly a performance optimization. Do
you
No. Did you read the part of my post starting with
'My motive for proposing the atomic keyword is that someone mentioned
"objects" and bitfields and that C++ doesn't have a "memory model".'
?
It _may_ be used as a performance optimization, but its main purpose would
be to resolve that defficiency of C++. Concurrent memory writes are
_usually_
atomic (eg. 'z.x=3') and there are no problems, as everything is
arbitrated by
the hardware.
Whether a memory access is atomic or not depends on the types
involved, the hardware architecture, and in some cases, the
actual address of the data. And of course, "atomic" is just the
tip of the iceberg; you also have to consider what other
processors see.
However if x is a bitfield, this will not be atomic if the
CPU lacks neccessary instructions.
Even if the CPU has the necessary instructions. I don't see how
updating a bitfield can be done "atomically".
Note that on some processors, the same thing is true for a byte;
a byte is handled exactly like a bit field.
[...]
Multithreading is inherently non-portable,
It doesn't have to be. Both Java and Ada specify portable
multithreading. I'm pretty sure that the next version of the
C++ standard will as well.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientie objet/
Beratung in objektorientierter Datenverarbeitung
9 place Simard, 78210 St.-Cyr-l'Icole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]