Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1081
| Newsgroups | comp.programming.threads |
|---|---|
| Date | 2012-09-20 00:50 -0700 |
| Message-ID | <0992cd7c-02bf-47e6-8c88-a171b7de8408@googlegroups.com> (permalink) |
| Subject | String multithreading issue |
| From | itt ium <ittium@gmail.com> |
Hi Group,
The following code when checked with helgrind shows possible race conditions. Is there a bug in std::string class?
void *do_work(void *)
{
std::string s;
s.erase();
return 0;
}
int main()
{
pthread_t tid[2];
pthread_create(&tid[0], NULL, do_work, NULL);
pthread_create(&tid[1], NULL, do_work, NULL);
return 0;
}
Helgrind output:
==11348== Helgrind, a thread error detector
==11348== Copyright (C) 2007-2012, and GNU GPL'd, by OpenWorks LLP et al.
==11348== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==11348== Command: ./a.out
==11348==
==11348== ---Thread-Announcement------------------------------------------
==11348==
==11348== Thread #3 was created
==11348== at 0xD01CE8: clone (in /lib/libc-2.5.so)
==11348== by 0x400B7F1: pthread_create_WRK (hg_intercepts.c:255)
==11348== by 0x400B8C2: pthread_create@* (hg_intercepts.c:286)
==11348== by 0x804861D: main (in /home/AMITAV/TEST/a.out)
==11348==
==11348== ---Thread-Announcement------------------------------------------
==11348==
==11348== Thread #2 was created
==11348== at 0xD01CE8: clone (in /lib/libc-2.5.so)
==11348== by 0x400B7F1: pthread_create_WRK (hg_intercepts.c:255)
==11348== by 0x400B8C2: pthread_create@* (hg_intercepts.c:286)
==11348== by 0x80485F7: main (in /home/AMITAV/TEST/a.out)
==11348==
==11348== ----------------------------------------------------------------
==11348==
==11348== Possible data race during read of size 4 at 0x7FEABB0 by thread #3
==11348== Locks held: none
==11348== at 0x7F96622: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== This conflicts with a previous write of size 4 by thread #2
==11348== Locks held: none
==11348== at 0x7F95E68: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== ----------------------------------------------------------------
==11348==
==11348== Possible data race during read of size 4 at 0x7FEABB8 by thread #3
==11348== Locks held: none
==11348== at 0x7F95E08: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== This conflicts with a previous write of size 4 by thread #2
==11348== Locks held: none
==11348== at 0x7F95E61: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== ----------------------------------------------------------------
==11348==
==11348== Possible data race during write of size 4 at 0x7FEABB8 by thread #3
==11348== Locks held: none
==11348== at 0x7F95E61: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== This conflicts with a previous write of size 4 by thread #2
==11348== Locks held: none
==11348== at 0x7F95E61: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== ----------------------------------------------------------------
==11348==
==11348== Possible data race during write of size 4 at 0x7FEABB0 by thread #3
==11348== Locks held: none
==11348== at 0x7F95E68: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== This conflicts with a previous write of size 4 by thread #2
==11348== Locks held: none
==11348== at 0x7F95E68: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== ----------------------------------------------------------------
==11348==
==11348== Possible data race during write of size 1 at 0x7FEABBC by thread #3
==11348== Locks held: none
==11348== at 0x7F95E6A: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348== This conflicts with a previous write of size 1 by thread #2
==11348== Locks held: none
==11348== at 0x7F95E6A: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x7F96646: std::string::erase(unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8)
==11348== by 0x8048658: do_work(void*) (in /home/AMITAV/TEST/a.out)
==11348== by 0x400B93D: mythread_wrapper (hg_intercepts.c:219)
==11348== by 0xDAB5AA: start_thread (in /lib/libpthread-2.5.so)
==11348== by 0xD01CFD: clone (in /lib/libc-2.5.so)
==11348==
==11348==
==11348== For counts of detected and suppressed errors, rerun with: -v
==11348== Use --history-level=approx or =none to gain increased speed, at
==11348== the cost of reduced accuracy of conflicting-access information
==11348== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)
Back to comp.programming.threads | Previous | Next — Next in thread | Find similar
String multithreading issue itt ium <ittium@gmail.com> - 2012-09-20 00:50 -0700
Re: String multithreading issue Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-09-20 11:54 +0200
Re: String multithreading issue bartek szurgot <basz@no.spam> - 2012-09-20 17:53 +0200
Re: String multithreading issue Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-09-21 08:09 +0200
Re: String multithreading issue Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2012-09-21 13:42 +0100
Re: String multithreading issue Marc <marc.glisse@gmail.com> - 2012-09-20 16:37 +0000
csiph-web