timer_shutdown_sync(9)
π timer_shutdown_sync β¨ Kernel API Manual
okay so bestie, gather round, because this here is timer_shutdown_sync(9) from the Kernel API Manual and it is literally the glow-up function you've been waiting for. π
πΈ NAME πΈ
timer_shutdown_sync β shut a timer down and make sure it can never, ever rearm itself again π
periodt.
β¨ SYNOPSIS β¨
int timer_shutdown_sync (struct timer_list *timer );
π¦ ARGUMENTS π¦
timerβ the timer you're shutting down. that's the whole vibe. that's the one. π«Ά
π₯ DESCRIPTION π₯
the way this works is: when the function returns, it is guaranteed that all of the following are true, no cap:
timeris not queued- The callback function of
timeris not running timercannot be enqueued again. Any attempt to rearmtimeris silently ignored.
for the synchronization rules, go read timer_delete_sync β that's where the receipts live. iykyk. π
this function is useful for final teardown of an infrastructure where the timer is subject to a circular dependency problem. and yes bestie, that is exactly as cursed as it sounds. π
a common pattern for this is a timer and a workqueue where the timer can schedule work and work can arm the timer. on shutdown the workqueue must be destroyed and the timer must be prevented from rearming. unless the code has conditionals like 'if (mything->in_shutdown)' to prevent that, there is no way to get this correct with timer_delete_sync. like, none. it's giving impossible. π
timer_shutdown_sync is solving the problem. the correct ordering of calls in this case is:
timer_shutdown_sync(mything->timer);
workqueue_destroy(mything->workqueue);
after this 'mything' can be safely freed. π¦β¨
and yes, this obviously implies that the timer is not required to be functional for the rest of the shutdown operation. main character timer doesn't need to keep working, she's retiring. π
β RETURN β
0β The timer was not pending1β The timer was pending
π SEE ALSO π
Kernel file ./kernel/time/timer.c:
struct timer_base(9)__round_jiffies_relative(9)round_jiffies(9)round_jiffies_relative(9)__round_jiffies_up_relative(9)round_jiffies_up(9)round_jiffies_up_relative(9)timer_init_key(9)mod_timer_pending(9)mod_timer(9)timer_reduce(9)add_timer(9)add_timer_local(9)add_timer_global(9)add_timer_on(9)__timer_delete(9)timer_delete(9)timer_shutdown(9)__try_to_del_timer_sync(9)timer_delete_sync_try(9)__timer_delete_sync(9)timer_delete_sync(9)fetch_next_timer_interrupt_remote(9)timer_unlock_remote_bases(9)timer_lock_remote_bases(9)timer_base_is_idle(9)timer_expire_remote(9)get_next_timer_interrupt(9)timer_base_try_to_set_idle(9)timer_clear_idle(9)__run_timers(9)
that's the whole page bestie, ily, go shut down some timers responsibly ππ
source: ./kernel/time Β· October 2026 Β· timer_shutdown_sync(9) π§β¨
π¦ 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