[cpp-threads] Prism 0.9.1, and further on the effects of races
Peter Dimov
pdimov at mmltd.net
Sat Sep 23 01:05:25 BST 2006
Boehm, Hans wrote in message c++std-ext-8018:
> My reaction:
>
> - The interaction of vtables and unordered atomics that Herb pointed
> out bothers me. We now have the potential of races on objects that
> are introduced by the implementation and not visible to the
> programmer.
The vtable is not an object in the C++ sense (1.8).
In:
// thread 1
px = new X;
// thread 2
px->f();
there is a race on the object *px of type X, regardless of whether this
object is polymorphic (may have a vtable.)
The lifetime of *px, when X has a non-trivial constructor, starts when its
constructor completes (3.8/1).
Accessing the object *px before its lifetime has started is undefined
behavior (3.8/5).
If the store to px doesn't have release semantics, thread 2 is not
guaranteed to observe the effects of the constructor, and hence, its
behavior is undefined.
When X has virtual functions, its default constructor is not trivial
(12.1/5). However, this is not the only way in which a type can have a
nontrivial default constructor.
In short, I believe that the vtable is a distraction; the problem is not
limited to types with vtables.
Even if you "fix" atomic<class_type_with_nontrivial_default*>, this doesn't
help with
// thread 1
px = new X( 1, 2 );
// thread 2
px->f();
since it uses a non-trivial constructor.
More information about the cpp-threads
mailing list