All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Boqun Feng" <boqun.feng@gmail.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>, "Tejun Heo" <tj@kernel.org>,
	"Tamir Duberstein" <tamird@gmail.com>,
	"Hamza Mahfooz" <hamzamahfooz@linux.microsoft.com>,
	"Alban Kurti" <kurti@invicto.ai>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [RFC PATCH] rust: workqueue: Add an example for try_spawn()
Date: Fri, 01 Aug 2025 10:54:26 +0200	[thread overview]
Message-ID: <DBQYQR7BPKQA.2UVOPCU6LXXAY@kernel.org> (raw)
In-Reply-To: <aIwVL9xmBFHcX9c4@Mac.home>

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

  reply	other threads:[~2025-08-01  8:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-30 16:34 [RFC PATCH] rust: workqueue: Add an example for try_spawn() Boqun Feng
2025-07-30 16:38 ` Miguel Ojeda
2025-07-30 18:48   ` Boqun Feng
2025-07-30 17:40 ` Joel Fernandes
2025-07-30 19:28 ` Benno Lossin
2025-07-30 19:38   ` Boqun Feng
2025-07-31  9:30     ` Benno Lossin
2025-08-01  1:15       ` Boqun Feng
2025-08-01  8:54         ` Benno Lossin [this message]
2025-08-01  9:05 ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DBQYQR7BPKQA.2UVOPCU6LXXAY@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=hamzamahfooz@linux.microsoft.com \
    --cc=joelagnelf@nvidia.com \
    --cc=kurti@invicto.ai \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tj@kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.