------- Additional Comments From davids at webmaster dot com  2005-02-20 19:43 
-------
>The reasoning is that dynamically created objects are often used locally in one
>thread, in which case locking would be unnecessary, while a singleton is always
>accessible to all threads.

Accessible, but not necessarily accessed. In fact, there is no way you can know
whether this synchronization overhead is necessary, and for POSIX it's only
needed if the code violates the memory visibility rules.

>Static locals in C++ are an equivalent to pthread_once in C/POSIX.

Even in the single-threaded case, C++ leaves it undefined what happens if you
reenter a function that invokes a static initializer from that static
initializer. To argue that this means it should be defined for the
multi-threaded case is absurd.

C++ requires the initialization to be complete before you are allowed to pass
the intializer again. POSIX requires locks when data that might be shared might
be modified.

Bluntly, this is totally opposite to the entire philosophy of the POSIX standard
and the wording of the C++ standard.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20099

Reply via email to