kthread_cancel_work_sync(9)
π 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 fordelayed_work's. like, don't do it. usekthread_cancel_delayed_work_syncinstead. 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β ifworkwas 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:
kthread_should_stop(9)kthread_should_park(9)kthread_freezable_should_stop(9)kthread_func(9)kthread_data(9)kthread_probe_data(9)kthread_complete_and_exit(9)kthread_create_on_node(9)kthread_bind(9)kthread_create_on_cpu(9)kthread_unpark(9)kthread_park(9)kthread_stop(9)kthread_stop_put(9)kthread_affine_preferred(9)kthreads_update_housekeeping(9)kthread_worker_fn(9)kthread_create_worker_on_node(9)kthread_create_worker_on_cpu(9)kthread_queue_work(9)kthread_delayed_work_timer_fn(9)kthread_queue_delayed_work(9)kthread_flush_work(9)kthread_mod_delayed_work(9)kthread_cancel_delayed_work_sync(9)kthread_flush_worker(9)kthread_destroy_worker(9)kthread_use_mm(9)kthread_unuse_mm(9)kthread_associate_blkcg(9)kthread_blkcg(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms