kthread_cancel_work_sync(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kthread_cancel_work_sync(9) πŸ’…

okay bestie, welcome to another ✨ Kernel API Manual ✨ page, and this one is kthread_cancel_work_sync(9) β€” yes the whole name is the title, we're not doing that in the first line, it's right here instead. let's get into it πŸŽ€


🌸 NAME 🌸

kthread_cancel_work_sync β€” cancel a kthread work and wait for it to finish. that's it. that's the whole vibe. πŸ¦‹


✨ SYNOPSIS ✨

bool kthread_cancel_work_sync (struct kthread_work *work );

it's giving "returns a bool", it's giving "takes exactly one pointer", we love a clean signature ngl πŸ’œ


🫢 ARGUMENTS 🫢

  • work β€” the kthread work you wanna cancel. that's the one, that's the target, point at it and go πŸ”₯

πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea β˜• β€” this function cancels work and waits for its execution to finish. like, not just "i asked it to stop", it's "i waited in the parking lot until it actually left" energy. periodt.

and the iconic part? you can use this even if the work re-queues itself β€” it handles that, no cap. on return from this function, work is guaranteed to be not pending or executing on any CPU. certified clean. πŸ’…βœ¨

⚠️ ok but listen β€” kthread_cancel_work_sync(delayed_work->work) must not be used for delayed_work's. like, don't do it. use kthread_cancel_delayed_work_sync instead. this is the one rule i'm gonna be annoying about πŸ™ˆ

also, the caller must ensure that the worker on which work was last queued can't be destroyed before this function returns. that's on you, bestie, not on the function. 🫑


🌈 RETURN 🌈

  • true β€” if work was pending 😭
  • false β€” otherwise 🧚

literally binary. slay.


πŸ’– SEE ALSO πŸ’–

okay this list is LONG, grab a snack πŸ“ β€” it's all in the kernel file ./kernel/kthread.c:


and that's the page!! 🌟 sign-off time: this lil masterpiece lives in ./kernel and it's dated October 2026, filed under kthread_cancel_work_sync(9). go cancel some work, synchronously, responsibly. mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from