Re: std::string bad design????
Mathias Gaunard wrote:
C++ gives no guarantee that simultaneous reads on const data
work. It is undefined behaviour.
The current C++ standard gives you no guarantee that
unsynchronized access from different to two different variables
works. One of the issues discussed in the committee involved
cases like:
char a ;
char b ;
where a and b were modifed by two different threads. There are
architectures where this requires special handling by the
compiler to ensure that it works.
The real problem is things like:
char a[ 2 ] ;
struct { int b1:4 ; int b2:4 ; } b ;
There's a pretty general consensus that unsynchronized accesses
to the same "object" are undefined behavior if any of the
accesses may modify the object. The question here is: are a[0]
and a[1] the same object, or different objects, and are b.b1 and
b.b2 the same object, or different objects? (I think that the
current thinking is that a[0] and a[1] are different objects,
and the compiler must do whatever is necessary to ensure that
the code works, even if the programmer modifies a[0] in one
thread, and a[1] in another. But that structure elements are
not guaranteed to be "different objects" if they are adjacent
bit fields.)
--
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! ]