Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-1056

std::moneypunct and std::numpunct implementations are not thread-safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 4.2.1, 4.2.x, 4.3.x, 5.0.0
    • 4.2.x, 4.3.x, 5.0.0
    • 22. Localization
    • 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

        1. punct.cpp.diff
          13 kB
          Stefan Teleman
        2. locale_body.cpp.diff
          7 kB
          Stefan Teleman
        3. facet.cpp.diff
          5 kB
          Stefan Teleman
        4. stdcxx-4.3.x-numpunct-perfect-forwarding.patch
          4 kB
          Liviu Nicoara
        5. stdcxx-4.2.x-numpunct-perfect-forwarding.patch
          3 kB
          Liviu Nicoara
        6. STDCXX-1056-additional-timings.tgz
          3 kB
          Liviu Nicoara
        7. stdcxx-1056-timings.tgz
          1 kB
          Liviu Nicoara
        8. runtests-linux64-all.out
          62 kB
          Stefan Teleman
        9. runtests-linux32-all.out
          62 kB
          Stefan Teleman
        10. runtests.out
          61 kB
          Stefan Teleman
        11. 22.locale.numpunct.mt.out
          19 kB
          Martin Sebor
        12. stdcxx-1056.patch
          4 kB
          Stefan Teleman

        Issue Links

          Activity

            People

              nikkoara Liviu Nicoara
              steleman Stefan Teleman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: