[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DBQYQR7BPKQA.2UVOPCU6LXXAY@kernel.org>
Date: Fri, 01 Aug 2025 10:54:26 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Boqun Feng" <boqun.feng@...il.com>
Cc: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
"Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>,
"Gary Guo" <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Andreas Hindborg" <a.hindborg@...nel.org>,
"Alice Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
"Danilo Krummrich" <dakr@...nel.org>, "Tejun Heo" <tj@...nel.org>, "Tamir
Duberstein" <tamird@...il.com>, "Hamza Mahfooz"
<hamzamahfooz@...ux.microsoft.com>, "Alban Kurti" <kurti@...icto.ai>, "Joel
Fernandes" <joelagnelf@...dia.com>, "Paul E. McKenney" <paulmck@...nel.org>
Subject: Re: [RFC PATCH] rust: workqueue: Add an example for try_spawn()
On Fri Aug 1, 2025 at 3:15 AM CEST, Boqun Feng wrote:
> On Thu, Jul 31, 2025 at 11:30:10AM +0200, Benno Lossin wrote:
>> On Wed Jul 30, 2025 at 9:38 PM CEST, Boqun Feng wrote:
>> > On Wed, Jul 30, 2025 at 09:28:05PM +0200, Benno Lossin wrote:
>> >> On Wed Jul 30, 2025 at 6:34 PM CEST, Boqun Feng wrote:
>> >> > + /// workqueue::system().try_spawn(
>> >> > + /// flags::GFP_KERNEL,
>> >> > + /// {
>> >> > + /// let work_done = work_done.clone();
>> >> > + /// let data = data.clone();
>> >> > + /// move || {
>> >> > + /// *data.lock() = 42;
>> >> > + /// work_done.complete_all();
>> >> > + /// }
>> >> > + /// }
>> >> > + /// )?;
>> >>
>> >> Not doing your pattern and instead adding a `2` postfix we get:
>> >>
>> >> let work_done2 = work_done.clone();
>> >> let data2 = data.clone();
>> >>
>> >
>> > Yeah, the thing I want to achieve with my pattern is: make it clear that
>> > the work and the task that queues the work are sharing the same
>> > `work_done` and `data` (well, no the same `Arc` exactly, but the `Arc`s
>> > that are pointing to the same object). This pattern here doesn't show
>> > that clearly imo.
>>
>> I think it's fine, that pattern is often used for that. Not heavily
>> opposed to doing it your way, but I feel like the code looks a bit weird
>
> Ok, I will drop my style and use work_done2 and data2, because it'll be
> at the general documentation, but I might keep using my pattern in other
> code because it looks reasonable to me ;-)
It is reasonable :) If you do want to use the same name for them, then I
personally think this looks better than moving the let bindings inside
of the expression:
{
let work_done = work_done.clone();
let data = data.clone();
workqueue::system().try_spawn(flags::GFP_KERNEL, move || {
*data.lock() = 42;
work_done.complete_all();
})?;
}
But that gives the `try_spawn` call extra indentation which also isn't
ideal... I'd be best for the language feature to exist :)
---
Cheers,
Benno
Powered by blists - more mailing lists