public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hideaki.kimura at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/60966] std::call_once sometime hangs
Date: Thu, 15 May 2014 03:13:00 -0000 [thread overview]
Message-ID: <bug-60966-4-FRAR2gzWK3@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-60966-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60966
--- Comment #14 from Hideaki Kimura <hideaki.kimura at gmail dot com> ---
(In reply to Jonathan Wakely from comment #13)
> This means you are waiting on an object that has gone out of scope. WIthout
> more information it's not possible to tell if this is a bug in your program
> or the standard libary.
>
> I'll try to reproduce it with Thomas's code...
Hey Jonathan,
I'm not sure if this helps, but could you try the following code snippet?
#include <future>
#include <iostream>
#include <thread>
#include <vector>
struct DummyTask {
DummyTask(int id) : id_(id) {}
int id_;
std::promise<void> pr;
};
const int THREADS = 100;
void run_task(DummyTask* task) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
task->pr.set_value();
}
void wait_for_task(DummyTask* task) {
task->pr.get_future().wait();
}
int main() {
std::vector<DummyTask*> tasks;
std::vector<std::thread*> threads;
for (int i = 0; i < THREADS; ++i) {
DummyTask* task = new DummyTask(i);
tasks.push_back(task);
threads.push_back(new std::thread(run_task, task));
}
for (int i = 0; i < THREADS; ++i) {
wait_for_task(tasks[i]);
// Because we returned from wait_for_task for this task, run_task is
surely done.
// No one else is referring to the task. So, even before
threads[i]->join(),
// it should be safe to delete it now.
delete tasks[i]; // but here you get an invalid read!
}
for (int i = 0; i < THREADS; ++i) {
threads[i]->join();
delete threads[i];
}
return 0;
}
Run it a few times on valgrind. You will see what I got.
If you move threads[i]->join() to the line before delete tasks[i], you don't
get the issue.
[Assuming that I'm not terribly missing something..]
My bet is that std::promise puts something on thread-local, which causes some
issue when std::promise's destructor is called before the corresponding
thread's join() is called.
next prev parent reply other threads:[~2014-05-15 3:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-25 13:57 [Bug libstdc++/60966] New: " thomas.sanchz at gmail dot com
2014-04-25 17:53 ` [Bug libstdc++/60966] " redi at gcc dot gnu.org
2014-04-25 18:36 ` redi at gcc dot gnu.org
2014-04-28 7:55 ` thomas.sanchz at gmail dot com
2014-04-28 8:09 ` thomas.sanchz at gmail dot com
2014-04-28 8:15 ` thomas.sanchz at gmail dot com
2014-04-28 8:22 ` redi at gcc dot gnu.org
2014-05-05 7:48 ` thomas.sanchz at gmail dot com
2014-05-05 15:16 ` redi at gcc dot gnu.org
2014-05-13 22:24 ` fawaka at gmail dot com
2014-05-14 1:58 ` hideaki.kimura at gmail dot com
2014-05-14 7:27 ` thomas.sanchz at gmail dot com
2014-05-14 10:43 ` redi at gcc dot gnu.org
2014-05-15 3:13 ` hideaki.kimura at gmail dot com [this message]
2014-05-15 21:05 ` redi at gcc dot gnu.org
2014-05-15 21:30 ` redi at gcc dot gnu.org
2014-05-15 22:02 ` hideaki.kimura at gmail dot com
2014-05-15 22:14 ` redi at gcc dot gnu.org
2014-05-15 22:55 ` redi at gcc dot gnu.org
2014-05-15 22:59 ` redi at gcc dot gnu.org
2014-05-15 23:39 ` redi at gcc dot gnu.org
2014-05-16 0:05 ` hideaki.kimura at gmail dot com
2014-05-16 0:15 ` redi at gcc dot gnu.org
2014-05-16 0:28 ` fawaka at gmail dot com
2014-05-16 7:18 ` redi at gcc dot gnu.org
2014-05-16 7:31 ` thomas.sanchz at gmail dot com
2014-05-17 12:59 ` redi at gcc dot gnu.org
2014-05-17 13:02 ` redi at gcc dot gnu.org
2014-05-17 13:09 ` redi at gcc dot gnu.org
2014-06-03 18:00 ` redi at gcc dot gnu.org
2014-06-03 18:01 ` redi at gcc dot gnu.org
2015-01-09 14:41 ` redi at gcc dot gnu.org
2015-01-09 14:41 ` redi at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-60966-4-FRAR2gzWK3@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).