Hello all,

I'm finding what appears to be a data race in the std::string class. Although I
find that hard to believe.

I am using libstdc++ 6.0.8, with g++ version 4.1.2 that is using the posix
thread model, on a Linux machine running SuSE SLES10SP1

     Linux <hostname> 2.6.16.46-0.12-smp #1 SMP Thu May 17 14:00:09 UTC 2007
     i686 i686 i386 GNU/Linux

My machine has 2 cores (or 4 hyper threads).

My application is a multithreaded, using boost threads, which in turn is using
posix pthreads under the sheets.


Below is one of many reports that all seem to be variations on the same
thing. If I read this correctly it is indicating that std::string in thread 1
and thread 8 are potentially racing.

thread1 and thread8 are absolutely not sharing any strings. Thread8's string is
a local stack string, and thread1's string appears to be another stack string
from inside the libboost_program_options.so-1.43.0

Am I reading this correctly? That there is a data race in the string class?

Thanks in advance for your help,

-=John


===============================================================================
Raw Data
----------------------------------------

==17936== Possible data race during write of size 4 at 0x43AF5D0 by thread #1
==17936== Locks held: none
==17936==    at 0x435DD45: std::string::_M_mutate(unsigned int, unsigned int, 
unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435DEA9: std::string::_M_replace_safe(unsigned int, unsigned 
int, char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435DF44: std::string::assign(char const*, unsigned int) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x457F9F2: 
boost::program_options::positional_options_description::add(char const*, int) 
(in lib/libboost_program_options.so.1.43.0)
==17936==    by 0x806D82F: process_args(int, char**, bool&) 
(MyProgramDaemon.cxx:130)
==17936==    by 0x806DF55: main (MyProgramDaemon.cxx:263)
==17936==    by 0x440D87B: __libc_start_main (in /lib/libc-2.4.so)
==17936==    by 0x806D170: ??? (in MyProgramDaemon)
==17936==
==17936== This conflicts with a previous read of size 4 by thread #8
==17936== Locks held: none
==17936==    at 0x435DF2E: std::string::assign(char const*, unsigned int) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435E0C4: std::string::operator=(char const*) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x4154C96: vee_gut_log(bool, bool, char const*, int, char 
const*, int, char const*, char const*, char*) (MyProgramLoggingCommon.cxx:71)
==17936==    by 0x4154F6F: ee_gut_log(bool, bool, char const*, int, char 
const*, 
int, char const*, char const*, ...) (MyProgramLoggingCommon.cxx:144)
==17936==    by 0x413CC53: sigThreadHdlr_c::sigThreadHdlr_main() 
(MyProgramSignalThreads.cxx:192)
==17936==    by 0x413CE02: sigThreadHdlr_c::sigThreadWrapper_main(void*) 
(MyProgramSignalThreads.cxx:54)
==17936==    by 0x402765D: mythread_wrapper (hg_intercepts.c:219)
==17936==    by 0x402765D: mythread_wrapper (hg_intercepts.c:219)


===============================================================================
Annotated version
----------------------------------------


==17936== Possible data race during write of size 4 at 0x43AF5D0 by thread #1
==17936== Locks held: none
==17936==    at 0x435DD45: std::string::_M_mutate(unsigned int, unsigned int, 
unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435DEA9: std::string::_M_replace_safe(unsigned int, unsigned 
int, char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435DF44: std::string::assign(char const*, unsigned int) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x457F9F2: 
boost::program_options::positional_options_description::add(char const*, int) 
(in lib/libboost_program_options.so.1.43.0)
==17936==    by 0x806D82F: process_args(int, char**, bool&) 
(MyProgramDaemon.cxx:130)

         pd.add("", -1);

==17936==    by 0x806DF55: main (MyProgramDaemon.cxx:263)
==17936==    by 0x440D87B: __libc_start_main (in /lib/libc-2.4.so)
==17936==    by 0x806D170: ??? (in MyProgramDaemon)
==17936==
==17936== This conflicts with a previous read of size 4 by thread #8
==17936== Locks held: none
==17936==    at 0x435DF2E: std::string::assign(char const*, unsigned int) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x435E0C4: std::string::operator=(char const*) (in 
/usr/lib/libstdc++.so.6.0.8)
==17936==    by 0x4154C96: vee_gut_log(bool, bool, char const*, int, char 
const*, int, char const*, char const*, char*) (MyProgramLoggingCommon.cxx:71)

     std::string    s_new_fmt;   // this is a local string
     ...
     ...
     s_new_fmt = p_func;


==17936==    by 0x4154F6F: ee_gut_log(bool, bool, char const*, int, char 
const*, 
int, char const*, char const*, ...) (MyProgramLoggingCommon.cxx:144)
==17936==    by 0x413CC53: sigThreadHdlr_c::sigThreadHdlr_main() 
(MyProgramSignalThreads.cxx:192)
==17936==    by 0x413CE02: sigThreadHdlr_c::sigThreadWrapper_main(void*) 
(MyProgramSignalThreads.cxx:54)
==17936==    by 0x402765D: mythread_wrapper (hg_intercepts.c:219)
==17936==    by 0x402765D: mythread_wrapper (hg_intercepts.c:219)


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to