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

std::string::operator+=(char) not thread-safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 4.1.2
    • 4.1.3
    • 21. Strings
    • None
    • all

    Description

      Discovered with SunPro 5.7 and reproducible also with SunPro 5.6 and gcc 3.4.3 but only on Solaris 10.

      $ cat t.cpp && nice gmake t && ./t
      #include <assert.h>
      #include <pthread.h>
      #include <string>

      const std::string str ("0123456789");
      const std::string expect = str + '*';

      extern "C" void* thread_func (void*)
      {
      for (int i = 0; i < 100000; ++i)

      { std::string s (str); s += '*'; assert (s == expect); }

      return 0;
      }

      int main ()
      {
      pthread_t tid [4];
      unsigned i = 0;

      for (i = 0; i != sizeof tid / sizeof *tid; ++i)

      { if (pthread_create (tid + i, 0, thread_func, (void*)0)) return 1; }

      for (i = 0; i != sizeof tid / sizeof *tid; ++i)

      { if (pthread_join (tid [i], 0)) return 2; }

      }
      CC -c -D_RWSTDDEBUG -mt -D_RWSTD_USE_CONFIG -I/build/sebor/sunpro-5.7.j4-15s/include -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/examples/include -library=%none -g +w t.cpp
      CC t.o -o t -library=%none -L/build/sebor/sunpro-5.7.j4-15s/lib -mt -L/build/sebor/sunpro-5.7.j4-15s/lib -lstd15s -lm
      Assertion failed: s == expect, file t.cpp, line 13
      Assertion failed: s == expect, file t.cpp, line 13
      Assertion failed: s == expect, file t.cpp, line 13
      Abort (core dumped)

      Attachments

        Activity

          People

            sebor Martin Sebor
            sebor Martin Sebor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: