public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/54185] New: condition_variable not properly destructed
@ 2012-08-06  4:19 architectbum at hotmail dot com
  2012-08-06  7:41 ` [Bug libstdc++/54185] " redi at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: architectbum at hotmail dot com @ 2012-08-06  4:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54185

             Bug #: 54185
           Summary: condition_variable not properly destructed
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: architectbum@hotmail.com


Created attachment 27947
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27947
a possible patch to solve the problem

The c11 standard (draft 3337, paragraph 30.5.1.5) states that
condition_variable may be destructed even if not all wait() calls have
returned, so long as all of those calls are blocking on the associated lock
rather than on *this. However, in gcc 4.7.1 the following snippets sometimes
fail with a segfault in thread A or simply inconsistent results:
  condition_variable *volatile cond = new condition_variable;
  // in thread A
    cond->wait();
  // in thread B, later
    cond->notify_all();
    delete cond;

It appears that the underlying libpthread also allows the destruction of cond
immediately after all blocking threads have been notified, by means of a block
in __pthread_cond_destroy while all of the wait() calls wake and begin to
reacquire their locks.

However, the current implementation in condition_variable.cc uses a default
destructor:
  condition_variable::~condition_variable() noexcept = default;
rather than calling __gthread_cond_destroy, and therefore the pthread cond
object is deleted without the block provided by __pthread_cond_destroy.

The attached patch seems to fix the problem with gcc-4.7.1 (verified on my
system, x86_64-pc-linux-gnu).

The patch undoes the replacement (in the presence of __GTHREAD_COND_INIT) of
~condition_variable with "= default" from
http://gcc.gnu.org/viewcvs?view=revision&revision=180411, which seems to have
been inadvertent.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-09-21 20:52 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-06  4:19 [Bug libstdc++/54185] New: condition_variable not properly destructed architectbum at hotmail dot com
2012-08-06  7:41 ` [Bug libstdc++/54185] " redi at gcc dot gnu.org
2012-08-06 14:19 ` architectbum at hotmail dot com
2012-08-06 14:20 ` architectbum at hotmail dot com
2012-08-06 14:30 ` redi at gcc dot gnu.org
2012-08-06 15:29 ` amonakov at gcc dot gnu.org
2012-08-06 17:18 ` architectbum at hotmail dot com
2012-08-12 16:22 ` redi at gcc dot gnu.org
2012-08-13 14:09 ` d.adler.s at gmail dot com
2012-08-13 14:35 ` redi at gcc dot gnu.org
2012-08-13 19:57 ` [Bug libstdc++/54185] [4.7/4.8 Regression] " redi at gcc dot gnu.org
2012-08-13 19:57 ` redi at gcc dot gnu.org
2012-08-13 19:57 ` redi at gcc dot gnu.org
2012-08-13 20:00 ` redi at gcc dot gnu.org
2020-08-13 21:37 ` lhyatt at gmail dot com
2020-08-13 21:55 ` redi at gcc dot gnu.org
2022-09-21 18:30 ` paul.groke at dynatrace dot com
2022-09-21 20:52 ` redi at gcc dot gnu.org

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).