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

From: Alice Ryhl

Date: Wed Nov 25 2026 - 13:18:02 EST


On Wed, Nov 25, 2026 at 06:44:05AM -1000, Tejun Heo wrote:
> Hello, Alice.
>
> On Thu, Nov 19, 2026 at 02:12:46PM +0000, Alice Ryhl wrote:
> > Because the cancellation guarantee only holds if the destructor runs
> > before the bound Queue or any lifetime in T expires, ScopedWork::new()
> > (and thus new_scoped_work!) is unsafe and requires that the resulting
> > value is never forgotten and is dropped before 'wq or T's lifetimes end.
>
> I'm no Rust expert, so maybe this is me thinking too much in C, but
> requiring the compiler to understand and enforce that a workqueue outlives
> its scoped work items doesn't seem very convenient to use. Wouldn't it be
> easier to package e.g. a percpu refcnt with the workqueue, have each scoped
> work item hold a reference from creation to destruction, and make
> destroy_workqueue() keep draining until the count reaches zero?

What I'd say is that this isn't the only way to spawn work on the
workqueue. This utility is intended for use-cases where it's convenient
to do it like that (e.g. because the queue is defined before the work
item in the same struct). We already have another way of spawning work
that uses different ownership rules (e.g. self-freeing work) and that
mechanism would not go through ScopedWork.

Alice