Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1082
| Date | 2012-09-20 11:54 +0200 |
|---|---|
| From | Marcel Müller <news.5.maazl@spamgourmet.com> |
| Newsgroups | comp.programming.threads |
| Subject | Re: String multithreading issue |
| References | <0992cd7c-02bf-47e6-8c88-a171b7de8408@googlegroups.com> |
| Message-ID | <505ae7f2$0$9512$9b4e6d93@newsspool1.arcor-online.net> (permalink) |
| Organization | Arcor |
On 20.09.2012 09:50, itt ium wrote:
> 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;
> }
There is nothing wrong with your code. And most likely there is nothing
wrong with std::string, too.
Most likely helgrind does not understand the way that string::erase is
implemented. I guess they add a reference to an existing empty string,
witch is immutable once the runtime has been initialized.
Sometimes small immutable contants are initialized lazy to avoid static
initialization sequence problems. This lazy initializations might be
implemented not fully thread-safe because there is no requirement that
all empty strings must refer to the same storage. In fact, more than one
instance might be created. But the latter is only wild guess.
Marcel
Back to comp.programming.threads | Previous | Next — Previous in thread | 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