Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2085423rwl; Thu, 30 Mar 2023 06:00:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJnczBOneswQvjOFzmGl+FtsuiQm0apX24rZi+kXsmOtTaiFa2JJueOyIK9LtT0a1VCR9q X-Received: by 2002:a05:6402:4315:b0:502:616b:cbd5 with SMTP id m21-20020a056402431500b00502616bcbd5mr2615877edc.2.1680181226334; Thu, 30 Mar 2023 06:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680181226; cv=none; d=google.com; s=arc-20160816; b=M2DQUMR8PVfECOGK6yTpqef6Fa7gKIu8Q9CMMAkLTW8JfnE2dW7rtGLHwUTXhCS34P cMrQpezDPcvxbarTiqaEmuakmxou1zzsLVP9KQXwUkER21TvzUvrbBGW+9Id+lk0mExL ADOUgAIbGbefEyGNNHvaQNlv+XbvAJlSeWS8V1gMROabMpon/RIaPc7CueNCnju/mMxB CI+GSIYV1IcGHJNcNV7muFiCeqA7oVRQQ8HUGDy5x9Zd0+Ww/b8Uoy8lkeqpo4m/Kt0y /LCicVJ4ASl0msXqTdxNzuFoQc8ZMzIMaqqRQMO2g8kLAVRGE4G989v3LV4bp+DfQ8Zj gErg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LbriNcVAfY0UBPuz6jCJeTcqNiFUFNZB08aDLtgpT/A=; b=rdgTM0TuPaUTbRxGsCgWzTw26f5B1aF4BC7pJ9xiQFiCLY+94ISmMBloZnr5zFkYgG PGYRlwQBf+STYyD/2qYojG/NvHX5qoykNFRe/6drfL0/3I5UYVunrJCt+osdFzdmZ3+7 8z8qbaZbZgH5+bnqQXG+XiXluRCPtEanxD/vlb8imSKxPHLbmtfvbwuFnNGmCQQrlaa4 2g2vfxHEOOfAS5AiwB7WfXIvtdbjJ5KPNtUgxgfs1M3Nk6ZtViWtLhkagR6OGtu3pdUB Uan1u0y7kfNaVgeQBBLSiE1lfTrONl8itSv5pdEejG26TBPUIq9CZtzhXzO7MzIRDA7T YvLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=G+wU3ww+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020aa7d3c9000000b004add56ba930si32113523edr.461.2023.03.30.05.59.59; Thu, 30 Mar 2023 06:00:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=G+wU3ww+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231590AbjC3Mwq (ORCPT + 99 others); Thu, 30 Mar 2023 08:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231585AbjC3Mwp (ORCPT ); Thu, 30 Mar 2023 08:52:45 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED1CC55B7; Thu, 30 Mar 2023 05:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LbriNcVAfY0UBPuz6jCJeTcqNiFUFNZB08aDLtgpT/A=; b=G+wU3ww+N8ZKrDEEm+k3MVeXsp AozFQ/e5GK+eLPLTHEo0asbNced1a6eoDaynCcHy5mXw8pwX0oUcequD4vH5zwIgaL4AVLSL5qOJW /AiQXMF7g+VF11RkCM9+cxbFHifxKqHN0+EWjyxOb06hSZU6pd2sYpQqvliROc68NT7M50FA4yR/4 sbSf5HhDp1axHNCwOy4mCxQYyOj9wTvVESS2CgRTpFTF2RMxi0zoQGF2S3q9JXzzZfu2l7nQAAHgE yfS5B9zCf0f2TXmC1av0tDEslPFeHeaWPu2N5lkT5/5A0ZSeNpwI8SqiUNSkaSj30Uco8HuKZmmHF nRS9J40Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1phrlQ-00APu7-0Q; Thu, 30 Mar 2023 12:52:25 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 716AE300134; Thu, 30 Mar 2023 14:52:23 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5101920134244; Thu, 30 Mar 2023 14:52:23 +0200 (CEST) Date: Thu, 30 Mar 2023 14:52:23 +0200 From: Peter Zijlstra To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , linux-kernel@vger.kernel.org, Wedson Almeida Filho , Ingo Molnar , Will Deacon , Waiman Long Subject: Re: [PATCH 12/13] rust: sync: introduce `CondVar` Message-ID: <20230330125223.GC124812@hirez.programming.kicks-ass.net> References: <20230330043954.562237-1-wedsonaf@gmail.com> <20230330043954.562237-12-wedsonaf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230330043954.562237-12-wedsonaf@gmail.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 30, 2023 at 01:39:53AM -0300, Wedson Almeida Filho wrote: > From: Wedson Almeida Filho > > This is the traditional condition variable or monitor synchronisation > primitive. It is implemented with C's `wait_queue_head_t`. > > It allows users to release a lock and go to sleep while guaranteeing > that notifications won't be missed. This is achieved by enqueuing a wait > entry before releasing the lock. > > +/// A conditional variable. > +/// > +/// Exposes the kernel's [`struct wait_queue_head`] as a condition variable. It allows the caller to > +/// atomically release the given lock and go to sleep. It reacquires the lock when it wakes up. And > +/// it wakes up when notified by another thread (via [`CondVar::notify_one`] or > +/// [`CondVar::notify_all`]) or because the thread received a signal. It may also wake up > +/// spuriously. Urgh so wide :-/ But no, threads can *always* and for any reason, have spurious wakeups. Also, is this hard tied to mutex? If so, you should probably use swait instead of wait.