public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99613] New: Static variable destruction order race condition
@ 2021-03-16 10:58 michalz at nvidia dot com
  2021-03-16 11:42 ` [Bug c++/99613] " rguenth at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: michalz at nvidia dot com @ 2021-03-16 10:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99613

            Bug ID: 99613
           Summary: Static variable destruction order race condition
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michalz at nvidia dot com
  Target Milestone: ---

Created attachment 50394
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50394&action=edit
Race condition demo

Function static variables should be destroyed in the reverse order of
initialization. However, the lock is released before calling atexit to register
the destructor, allowing for a race condition to occur if multiple threads are
accessing static variables for the first time.

The bug affects all versions of GCC that I've tried (6.4, 7.3, 8.2, 9.3, 10.2)
on multiple platforms.

The error in output assembly can be seen when compiling the following code:

struct S{
   S();
   ~S();
};

S& foo(){
    static S s;
    return s;
}

The attached file contains a working example that triggers the race condition
(it's a race condition, so sometimes it succeeds).

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

end of thread, other threads:[~2021-09-11 14:22 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 10:58 [Bug c++/99613] New: Static variable destruction order race condition michalz at nvidia dot com
2021-03-16 11:42 ` [Bug c++/99613] " rguenth at gcc dot gnu.org
2021-03-16 12:23 ` jakub at gcc dot gnu.org
2021-03-16 12:35 ` jakub at gcc dot gnu.org
2021-03-16 12:37 ` michalz at nvidia dot com
2021-03-16 12:42 ` jakub at gcc dot gnu.org
2021-03-16 12:48 ` rguenth at gcc dot gnu.org
2021-03-16 12:56 ` jakub at gcc dot gnu.org
2021-03-16 13:04 ` michalz at nvidia dot com
2021-03-16 13:07 ` michalz at nvidia dot com
2021-03-16 13:15 ` jakub at gcc dot gnu.org
2021-03-16 13:24 ` michalz at nvidia dot com
2021-03-16 13:25 ` michalz at nvidia dot com
2021-03-16 13:35 ` jakub at gcc dot gnu.org
2021-03-16 14:05 ` michalz at nvidia dot com
2021-03-16 14:07 ` jacobhemstad at gmail dot com
2021-03-16 14:23 ` jakub at gcc dot gnu.org
2021-03-16 14:38 ` rguenth at gcc dot gnu.org
2021-03-16 20:18 ` cvs-commit at gcc dot gnu.org
2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
2021-04-20 23:33 ` cvs-commit at gcc dot gnu.org
2021-04-22 16:51 ` cvs-commit at gcc dot gnu.org
2021-04-22 17:10 ` jakub at gcc dot gnu.org
2021-09-11 14:22 ` pinskia 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).