From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7286F3858CDB; Mon, 10 Jun 2024 17:33:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7286F3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718040814; bh=3rw/fVV97uqBP5H8P7MMtGkvaoC0NgB4rDzIfeoAlcg=; h=From:To:Subject:Date:From; b=mUN+DGcQmgO0oZyuBmFXXvSdBvA8Sf5VF+wvza2gvqTLq7iOQv2stu2VWo7UuWsSe A4tTttMnwCJRfm3NtLMB0en6Eef9mv4a1mhZOBr28wwJ4T19MdH+iaL+LQCWWUYT5C zpHyNhevgV8dKUzea+ORHm0y2obka23j17TBVPDg= From: "ilg at livius dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115422] New: Multi-threaded condition_variable app throws when linking as -static on Linux Date: Mon, 10 Jun 2024 17:33:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 14.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ilg at livius dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115422 Bug ID: 115422 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: --- 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 whe= n 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.=20 The source code is attached.inside=20 The problem seems to be the global condition variable and/or mutex; if I mo= ve 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++?=