Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
4.2.1, 4.2.x, 4.3.x, 5.0.0
-
Solaris 10 and 11, RedHat and OpenSuSE Linux, Sun C++ Compilers 12.1, 12.2, 12.3
Issue is independent of platform and/or compiler.
-
Patch Available
-
Unit Test Broken
-
Incorrect Behavior
Description
several member functions in std::moneypunct<> and std::numpunct<> return
a std::string by value (as required by the Standard). The implication of return-by-value
being that the caller "owns" the returned object.
In the stdcxx implementation, the std::basic_string copy constructor uses a shared
underlying buffer implementation. This shared buffer creates the first problem for
these classes: although the std::string object returned by value appears to be owned
by the caller, it is, in fact, not.
In a mult-threaded environment, this underlying shared buffer can be subsequently modified by a different thread than the one who made the initial call. Furthermore, two or more different threads can access the same shared buffer at the same time, and modify it, resulting in undefined run-time behavior.
The cure for this defect has two parts:
1. the member functions in question must truly return a copy by avoiding a call to the copy constructor, and using a constructor which creates a deep copy of the std::string.
2. access to these member functions must be serialized, in order to guarantee atomicity
of the creation of the std::string being returned by value.
Patch for 4.2.1 to follow.
Attachments
Attachments
Issue Links
- is related to
-
STDCXX-1071 numpunct facet cache initialization is not thread -safe
- Open