On Wed, Apr 7, 2010 at 3:32 AM, Jorge Moraleda <[email protected]> wrote:
>
> >
> > #include <pthread.h>
> > #include <string>
> > #include <sstream>
> >
> > void *threadEntry(void *threadid)
> > {
> >   long tid;
> >   tid = (long)threadid;
> >         std::string myString;
> >         for (int i = 0; i<5; i++) {
> >                 myString.clear();
> >                 pthread_yield();
> >         }
> >         pthread_exit(NULL);
> > }
> >
> > int main (int argc, char *argv[])
> > {
> >   pthread_t threads[2];
> >   int rc;
> >   long t;
> >
> >         std::ostringstream dummy;
> >         dummy << 0;
> >         for(t=0; t<2; t++) {
> >                 rc = pthread_create(&threads[t], NULL, threadEntry, (void 
> > *)t);
> >         }
> >         pthread_exit(NULL);
> > }
> >
> > ==19065== drd, a thread error detector
> > ==19065== Copyright (C) 2006-2009, and GNU GPL'd, by Bart Van Assche.
> > ==19065== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for
> > copyright info
> > ==19065== Command: ./a.out
> > ==19065==
> > ==19065== Thread 3:
> > ==19065== Conflicting load by thread 3 at 0x05134160 size 8
> > ==19065==    at 0x4EDF1D7: std::string::clear() (in
> > /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065== Conflicting load by thread 3 at 0x05134160 size 8
> > ==19065==    at 0x4EDE907: std::string::_M_mutate(unsigned long,
> > unsigned long, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065== Conflicting load by thread 3 at 0x05134170 size 4
> > ==19065==    at 0x4EDE9B0: std::string::_M_mutate(unsigned long,
> > unsigned long, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065== Conflicting store by thread 3 at 0x05134170 size 4
> > ==19065==    at 0x4EDE97D: std::string::_M_mutate(unsigned long,
> > unsigned long, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065== Conflicting store by thread 3 at 0x05134160 size 8
> > ==19065==    at 0x4EDE984: std::string::_M_mutate(unsigned long,
> > unsigned long, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065== Conflicting store by thread 3 at 0x05134178 size 1
> > ==19065==    at 0x4EDE987: std::string::_M_mutate(unsigned long,
> > unsigned long, unsigned long) (in /usr/lib/libstdc++.so.6.0.13)
> > ==19065==    by 0x400A5B: threadEntry(void*) (threads.cpp:12)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.13
> > ==19065== Other segment start (thread 2)
> > ==19065==    at 0x58DD7D1: clone (clone.S:84)
> > ==19065==    by 0x55E893F: ??? (allocatestack.c:743)
> > ==19065==    by 0x676D90F: ???
> > ==19065== Other segment end (thread 2)
> > ==19065==    at 0x58ACEB7: sched_yield (in /lib/libc-2.10.1.so)
> > ==19065==    by 0x400A60: threadEntry(void*) (threads.cpp:13)
> > ==19065==    by 0x4C32870: vgDrd_thread_wrapper 
> > (drd_pthread_intercepts.c:272)
> > ==19065==    by 0x55E8A03: start_thread (pthread_create.c:300)
> > ==19065==    by 0x58DD80C: clone (clone.S:112)
> > ==19065==
> > ==19065==
> > ==19065== For counts of detected and suppressed errors, rerun with: -v
> > ==19065== ERROR SUMMARY: 54 errors from 6 contexts (suppressed: 205 from 
> > 142)
> >
> > Are all the race conditions in  I/O code in libstdc++ bening?

They should -- each race in libstdc++ that is not benign is a bug.

> > If so, are there more things that I should initialize in my app before
> > I start creating threads and/or should I be looking into creating
> > suppression patterns for drd? Has anyone created them before? Why are
> > they not enabled by default in drd?
> >
> > If not... What should I be reading,doing? Thank you in advance.
>
> I found the following bug-report against gcc:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40518
> It seems that the problem is fixed in gcc 4.5. Until it is released, I
> added code to my application to not clear empty strings, and it seems
> to solve all the these problems. Thank you very much.

Thanks for the gcc bugzilla link -- that bug report is interesting.
Since the races on _S_empty_rep_storage are false positives, it is
safe to suppress these races. You can suppress these races using the
following dirty hack:
* add #include "drd/drd.h" in the same source file that contains the
main() function.
* add the following code near the beginning of the main() function:

    extern char _ZNSs4_Rep20_S_empty_rep_storageE[32];
    DRD_IGNORE_VAR(_ZNSs4_Rep20_S_empty_rep_storageE);

The above two statements tell DRD to ignore all load and store
operations in the 32-byte address range starting at
&std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::_Rep::_S_empty_rep_storage.

Note: from Valgrind 3.6.0 on DRD will support the
ANNOTATE_BENIGN_RACE_SIZED() macro. This macro does the same as
DRD_IGNORE_VAR() but has an explicit size argument.

Bart.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to