public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <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 22:55:00 -0000	[thread overview]
Message-ID: <bug-60966-4-l5RgoQzHSi@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 #19 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #16)
> The easiest fix is to call get_future() before passing the task into a new
> thread, and store it in a std::vector<std::future<void>>

Actually this only hides the error (by ensuring the shared state is not deleted
because there is a future object still referring to it) but the fundamental
problem with that code remains:

You are calling the promise destructor before the call to set_value()
completes.

You are assuming that as soon as the shared state becomes ready the promise is
no longer in use, but that's not true. After the shared state is made ready the
rest of the set_value() function runs, which accesses members of the shared
state. If you destroy the promise (and it has the only reference to the shared
state) then it will destroy its members while they are still being used.

This is a bug in your code, std::promise is like any other type: you must not
delete it while another thread is still using it.


  parent reply	other threads:[~2014-05-15 22:55 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
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 [this message]
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-l5RgoQzHSi@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).