From nobody Sat Jul 25 20:05:11 2026 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4h6wny275gz6m1dF for ; Sat, 25 Jul 2026 20:05:26 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4h6wnx5Vpyz3g15 for ; Sat, 25 Jul 2026 20:05:25 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 66PK5BOv064162; Sat, 25 Jul 2026 23:05:14 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 66PK5BOv064162 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 66PK5BG0064161; Sat, 25 Jul 2026 23:05:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 25 Jul 2026 23:05:11 +0300 From: Konstantin Belousov To: Dmitry Morozovsky Cc: freebsd-hackers@freebsd.org Subject: Re: pthread_cond_wait spurious wakeup Message-ID: References: <20260724230235.GB39748@zxy.spb.ru> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.2 X-Spam-Checker-Version: SpamAssassin 4.0.2 (2025-08-27) on tom.home X-Rspamd-Queue-Id: 4h6wnx5Vpyz3g15 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Spamd-Bar: ---- On Sat, Jul 25, 2026 at 02:06:31PM +0300, Dmitry Morozovsky wrote: > > On 25.07.2026 2:41, Konstantin Belousov wrote: > > On Sat, Jul 25, 2026 at 02:02:35AM +0300, Slawa Olhovchenkov wrote: > > > Is pthread_cond_wait susceptible to spurious wakeup in FreeBSD? The > > > pthread_cond_wait man page doesn't say anything about waiting thread > > > can unblocking in cases like EINTR. But in > > > lib/libthr/thread/thr_cond.c:232-249, > > > I seem to see a successful return from pthread_cond_wait on EINTR > > > case. So, we don't have a spurious wakeup issue, or does the man page > > > need to be corrected and an additional predicate should be used in > > > conjunction with pthread_cond_wait? > > Spurious wakeups are allowed and can happen. They are not neccessarly > > limited to signals delivery. > > > > 'The additional predicate' is how the user code must be structured anyway, > > because pthread_cond_wait() drops the mutex that is supposed to protect > > the data holding the condition. > > So, is the wording > > "The waiting thread unblocks only after..." > > from the manpage wrong (incomplete)? > > And, if yes, how do you think should it be rephrased/corrected? https://reviews.freebsd.org/D58458