Re: [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items
From: Tejun Heo
Date: Wed Nov 25 2026 - 11:44:13 EST
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?
Thanks.
--
tejun