From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21D24225D6; Thu, 3 Jul 2025 07:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751529079; cv=none; b=V8cIlJsimy6W2bhUpW7AmX/7cVQAwFPtltb717cbDQFetNFNIZ4PZwdmD19epL2p4NHf/gzY7AY5nsDrzIA3lx4ubJSNkRMITGzA1wiQY/4gi0ZBA/bo5ToQ2LTDYKbLa6NCwZyb/DmCJURHWq5u80b9siCWHOyfkrt2ZJRwKjI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751529079; c=relaxed/simple; bh=RjRLZxr33+J8jGIO+4wFE0QODeYW14cbDpVhMRCXyzg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=LJHTY52kG69aQfMUBCYVCioR8K0xCcdm8NuGsTSfXmZzewr9Y9J/rTx4IHLemHdfsUDkEOSFW9Nd0+Q33qXJpWH8519b6mygKgOUmBUAKds7E55dfZkA07G1vw/whLRD64bgDTkjQngUl05hFmHihpTKObiS+beQsWJzeMkEt8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NSfuUiOA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NSfuUiOA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02BEDC4CEE3; Thu, 3 Jul 2025 07:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751529078; bh=RjRLZxr33+J8jGIO+4wFE0QODeYW14cbDpVhMRCXyzg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NSfuUiOASqRQpZFRrGCU7ZUHkLJc7KgPAY5TYu+KdCpmFzw1+YucYfWmsSXzFhDEQ FVJIeIFUDxpa3JpCSqMf1WhopmXCPb2dSToLwdewUyRADFMrbCHVjPZJ45Wa+LuY+1 m2eBMiwbSQFo4GIVNtKJ9aiBru81ZBB8z8/nuAlyQ7MoX8Oyo1zLAQBc2Lc6fvEHbb EgqvTWIU51NqDkvJE0xbfWhx0y4xfSIDU1EtrM1DlEysM1dAmWanls/liGVmtKErF9 2t5IdX5wW0VOHTcTWJmCe5HAOZNWuz4UkLHmtH0dNmZ9yKIpS+OL6rpk4+rWz/WZo7 oCWog3bdFmU2w== From: Andreas Hindborg To: "Alice Ryhl" Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Benno Lossin" , "Nicolas Schier" , "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v14 1/7] rust: sync: add `OnceLock` In-Reply-To: (Alice Ryhl's message of "Wed, 02 Jul 2025 16:50:30 +0200") References: <20250702-module-params-v3-v14-0-5b1cc32311af@kernel.org> <20250702-module-params-v3-v14-1-5b1cc32311af@kernel.org> <87ms9mvgu4.fsf@kernel.org> User-Agent: mu4e 1.12.9; emacs 30.1 Date: Thu, 03 Jul 2025 09:51:06 +0200 Message-ID: <87h5ztvhjp.fsf@kernel.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable "Alice Ryhl" writes: > On Wed, Jul 2, 2025 at 3:54=E2=80=AFPM Andreas Hindborg wrote: >> >> "Alice Ryhl" writes: >> >> > On Wed, Jul 2, 2025 at 3:19=E2=80=AFPM Andreas Hindborg wrote: >> >> >> >> Introduce the `OnceLock` type, a container that can only be written o= nce. >> >> The container uses an internal atomic to synchronize writes to the in= ternal >> >> value. >> >> >> >> Signed-off-by: Andreas Hindborg >> > >> > This type provides no way to wait for initialization to finish if it's >> > ongoing. Do you not need that? >> >> I don't, and in my use case it would cause a deadlock to wait. Anyway, >> it might be useful to others. Would you add it now, or wait for a user? > > Waiting would require additional fields so it should probably be a > different type. That depends on the kind of waiting. If we do unfair waiting, with spinning, we can have unlimited waiters with this type. We can also use the remaining 29 bits of the atomic to encode ordering to get fair queuing for spinning waiters. Putting waiters to sleep would require more fields. > It's more that we probably want the OnceLock name for > that other type for consistency with stdlib, so perhaps this should be > renamed? The name could be SetOnce or similar. The feature set is very similar to `std::sync::OnceLock`, that is why I picked that name. We can expand this to allow resetting without too much effort, and we can do fair waiting with spinning for a reasonable amount of waiters. But I am also OK with changing the name to `SetOnce` if we envision a `OnceLock` with thread sleep blocking at some point. Best regards, Andreas Hindborg