From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9790 invoked from network); 2 Jul 2022 17:56:18 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 2 Jul 2022 17:56:18 -0000 Received: (qmail 7292 invoked by uid 550); 2 Jul 2022 17:56:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7257 invoked from network); 2 Jul 2022 17:56:15 -0000 Date: Sat, 2 Jul 2022 13:56:02 -0400 From: Rich Felker To: William Tang Cc: musl@lists.openwall.com Message-ID: <20220702175602.GV7074@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Spurious wake up in musl On Sun, Jul 03, 2022 at 12:38:05AM +0800, William Tang wrote: > Hi, > > According to the about page, the spurious wake up should not be possible: That is not a correct reading. Spurious wakes are always possible. > musl was the first Linux libc to have ..., the first to have condvars > where newly-arrived waiters can't steal wake events from previous > waiters > > However, when I use the following code to test spurious wake up: > [...] > > And compile with command "musl-gcc -static main.c", it outputs: > [main] Started working threads: 0x7efc7f212f38, 0x7efc7f1eff38 > [worker 0x7efc7f212f38] No more work need to be done! > [worker 0x7efc7f1eff38] No more work need to be done! > [worker 0x7efc7f1eff38] No more work need to be done! > [worker 0x7efc7f1eff38] No more work need to be done! > [worker 0x7efc7f212f38] Spurious wakeup occurred! Counter is 0! These aren't contradictory. The guarantee is that wakes won't be missed due to a newly-arriving waiter stealing one that should have been seen by an already-present waiter. You seem to be reading that in a sort of converse-direction as implying a waiter won't wake spuriously -- maybe assuming a spurious wake would be stealing the wake from another waiter, but that's not what's happening. Spuriou wakes are an inherent part of using condvars, and any logic that depends on them not happening is missing the point of how condvars work and how they're supposed to be used. Rich