From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 786A01607BD; Tue, 6 Aug 2024 09:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722936470; cv=none; b=Bhgy7y00tlP6lWfJAH343m8EKvbpHcT61Z2k2H0Sm1BY1u2nrvdeFj+8lMw8UzNJH4/xtSgjqQDfE1sN3bLkYKsc3Sn6JYBHqf/EQkH4i7QI0SMWf6sjqhLfL5e5JdsHEKm5DsuSqQsKYcosW1AIQtcnwxJne9KujS06+BvUbm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722936470; c=relaxed/simple; bh=7sPbgXjAAEJtXFHk0SLmRdhHDyevcomFeceOUjfG9Sg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iy7IS1a6e+HLc8Af+VyhJ3gUSKHbdX/YnX5U/sUcbA8mZnZKsW1edeNizZ5YNgl2ObrUr6t5zH5yFkQONZErcegABXXeaKatK5rNnQ5ZjHY2Yw8UUQw/sqSUQ098GTdl28IBzR2jKK8w4SVHSvoJWGNdNseEqDJnuLRoeJzbmqE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=fyzDO43g; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="fyzDO43g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1722936455; x=1723195655; bh=QtfHhNVL/fDZI1RcLFsBz/E+dffq3r9sCPeAFCaPUwU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=fyzDO43gjcKljxhbfec5pSJF3YbmImFPjpC8V3Q8HyrxfEDDHxJ7GCrTC6rY5VeBw yd4l725NDJ+p3oFVij5KoFVA6/2iJMa3Mw9xRdd3+TIlJe3OfV6JJzw0Gd+DAJrJdc mF0didLDoGGOwIA2fK0sMJjMBN/1sVCPrvcbmiR/0kotsbYaGvLzPyjGGjPPutbv17 WKXDv4iG/kd0lxTlo0xQDVwOGJ4anklspl3DvmFWr3+Kgi5AHBVmLmf4oK2ACN6BHj lFHq+Tz63Jns0GmMDjt/M8uXyVUf3ON7FAaornh+2k5+hdWwpnSGy88vvHz7fBVCU6 BX2DcC0ZpUucg== Date: Tue, 06 Aug 2024 09:27:29 +0000 To: Alice Ryhl From: Benno Lossin Cc: Matt Gilbride , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Christian Brauner , Rob Landley , Davidlohr Bueso , Michel Lespinasse , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 5/6] rust: rbtree: add `RBTreeCursor` Message-ID: <4a1b6a7a-9d0c-4089-bc14-0fe629a56d3e@proton.me> In-Reply-To: References: <20240727-b4-rbtree-v8-0-951600ada434@google.com> <20240727-b4-rbtree-v8-5-951600ada434@google.com> <309d3d27-62d0-42b0-b50a-40692a019b40@proton.me> <4ef9616f-a35a-4aa2-993c-9b67f50a46ee@proton.me> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 285a73cad60a0c1f3ea661eebb3b461d0430e2d9 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 On 06.08.24 11:04, Alice Ryhl wrote: > On Tue, Aug 6, 2024 at 11:01=E2=80=AFAM Benno Lossin wrote: >> >> On 06.08.24 10:24, Alice Ryhl wrote: >>> On Mon, Aug 5, 2024 at 9:35=E2=80=AFPM Benno Lossin wrote: >>>> On 27.07.24 22:30, Matt Gilbride wrote: >>>>> + tree: &'a mut RBTree, >>>>> + current: NonNull, >>>>> +} >>>>> + >>>>> +// SAFETY: The [`RBTreeCursor`] gives out immutable references to K = and mutable references to V, >>>>> +// so it has the same thread safety requirements as mutable referenc= es. >>>>> +unsafe impl<'a, K: Send, V: Send> Send for RBTreeCursor<'a, K, V> {} >>>> >>>> Again, do we want to use `K: Sync` here instead? >>> >>> In this case, `K: Send` and `K: Sync` are both sufficient conditions, >>> but `K: Send` will generally be less restrictive for the user. >> >> What if `K =3D struct(RefCell, i32)` where only the second i32 is >> used in `(Partial)Ord`? Then you can send `RBTreeCursor` to another >> thread and call `borrow` there, even though `K: !Sync` (and the value >> still lives on another thread). >=20 > In that scenario, all immutable references to the key would be on the > same thread as the cursor. The cursor borrows the tree mutably, so > there can only be one cursor. >=20 > When using `K: Send`, it's basically like having `RBTreeCursor` store > mutable references to the key, but with an API that downgrades to > immutable reference when giving out access to the key. Ah that's true. --- Cheers, Benno