Re: [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items

From: Philipp Stanner

Date: Mon Nov 30 2026 - 12:02:33 EST


Howdy, just 2 cents from me:

On Fri, 2026-11-27 at 06:12 -1000, Tejun Heo wrote:
> I didn't explain myself well. I'm not saying that the current scheme
> doesn't work. My concern is how easy the interface is to use, and I wonder
> whether taking workqueue lifetime out of the compiler-managed lifetime
> rules could make it simpler. Something like the following:

[…]

> Workqueue looks the way it does because it's C and leaves all lifetime
> management to its users. Carrying the same model over to Rust and then
> wrapping it for each use case seems like a missed opportunity. I don't
> know Rust well, so I could just be blowing hot air.

The thing is that in C the only real tools for lifetime management at
our disposal are either doing it right manually with discipline, or to
do refcounting.

Exposed refcounting, as Danilo pointed out many times, has the
disadvantage of objects being able to live longer than they should,
like outliving driver unbind.

Next to refcounting, Rust has borrow-checked lifetimes. IMO you are
right that they make the code more difficult to write and read.

But effectively, if you do "internal refcounting" then you just *re-
implement* lifetime-checked references with refcounts: an internal
refcount, wrapped-away for the user, and constructors and destructors
(in?)transparently manage the count.

Whereas with lifetimes the rules of drop order become visible to the
user directly. Which is what you want, basically: tear down A before B.

Refcounts would then, in this "Rust model", be the tool of choice if
you really *don't know* how long something shall live, for example with
objects you loan to userspace.


Greetings,
Philipp