public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/115421] New: Multi-threaded condition_variable app throws when linking as -static on Linux
@ 2024-06-10 17:32 ilg at livius dot net
  2024-06-10 17:35 ` [Bug libstdc++/115421] " pinskia at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: ilg at livius dot net @ 2024-06-10 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115421
           Summary: Multi-threaded condition_variable app throws when
                    linking as -static on Linux
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ilg at livius dot net
  Target Milestone: ---

Created attachment 58398
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58398&action=edit
The test source code

I have a test that checks C++ threads which synchronise via a
condition_variable.

The test runs fine on Linux/macOS/Windows, in various scenarios, except when I
build it as `-static` on Linux.

```
$ g++ sleepy-threads-cv.cpp -o sleepy-threads-cv -static -g -lpthread
$ ./static-sleepy-threads-cv 4
abcd
$ g++ sleepy-threads-cv.cpp -o static-sleepy-threads-cv -static -g -lpthread
$ ./static-sleepy-threads-cv 4
Segmentation fault
```

On some systems the result is an exception:

```
terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
```

I encountered the issue while building the xPack GCC 14 binaries, but later
confirmed it on GCC 13 and older. 

The source code is attached.inside 

The problem seems to be the global condition variable and/or mutex; if I move
them inside the `spawnThreads()` function and pass pointers to them to all
threads, the test is functional even with `-static`.

Is there anything wrong with my test, or is this a small bug in libstdc++?

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

end of thread, other threads:[~2024-06-11  9:39 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-10 17:32 [Bug libstdc++/115421] New: Multi-threaded condition_variable app throws when linking as -static on Linux ilg at livius dot net
2024-06-10 17:35 ` [Bug libstdc++/115421] " pinskia at gcc dot gnu.org
2024-06-10 17:36 ` pinskia at gcc dot gnu.org
2024-06-10 17:38 ` pinskia at gcc dot gnu.org
2024-06-10 17:42 ` pinskia at gcc dot gnu.org
2024-06-10 17:56 ` ilg at livius dot net
2024-06-10 18:00 ` pinskia at gcc dot gnu.org
2024-06-10 18:08 ` pinskia at gcc dot gnu.org
2024-06-10 18:13 ` ilg at livius dot net
2024-06-10 18:16 ` sjames at gcc dot gnu.org
2024-06-10 18:22 ` ilg at livius dot net
2024-06-10 18:26 ` ilg at livius dot net
2024-06-10 18:49 ` ilg at livius dot net
2024-06-10 18:52 ` pinskia at gcc dot gnu.org
2024-06-11  9:26 ` redi at gcc dot gnu.org
2024-06-11  9:27 ` redi at gcc dot gnu.org
2024-06-11  9:39 ` rguenth 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).