Date: Sat, 2 Jul 2022 13:56:02 -0400 From: Rich Felker <dalias@...c.org> To: William Tang <galaxyking0419@...il.com> Cc: musl@...ts.openwall.com Subject: Re: 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.