From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BBD183858C55; Tue, 20 Sep 2022 15:45:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBD183858C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663688740; bh=m7BFolG+IOZKsUdU8gjt1FZh/EeaB/yM+SdrLsMRF/4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mFP89kdlRGnC4ij4cC7nfNxqdsVGrVP/Qm+F7fGhswQ+eUXjMKf5/QS9RNWWr8Iu4 pku7GV7aV2j4XyMrtQLj0VtJqcn3cUBQMRm0mTCICuJBHgMOLPYCBeoOOK2E5TQjiz BwoHW9OHcxuimp8ZMJkmqtS1yKPulQ0ZXpW9Eotc= From: "valera.mironow at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/106772] atomic::wait shouldn't touch waiter pool if used platform wait Date: Tue, 20 Sep 2022 15:45:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: valera.mironow at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: Message-ID: In-Reply-To: References: 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=3D106772 --- Comment #13 from Mkkt Bkkt --- example of simple mutex pseudocode that don't need call notify every unlock: Same possible for other cases, if it doesn't please share example for me ``` int kUnlocked =3D 0; int kLocked =3D 1; int kLockedWithWaiters =3D 2; std::atomic state{0}; lock: // some spin if (state.cas(kUnlocked, kLocked)) { return; } do { if (state =3D=3D kLockedWithWaiters || state.cas(kLocked, kLockedWithWa= iters)) { state.wait(kLockedWithWaiters); } } while (!state.cas(kUnlocked, kLockedWithWaiters)); unlock: if (state.exchange(kUnlocked) =3D=3D kLockedWithWaiters) { state.notify_one(); } ```=