Skip to content

Commit 7575cf0

Browse files
committed
Add flush_workqueue before destroying workqueue
To ensure no work is left running when the module is removed, call flush_workqueue() before destroy_workqueue() in the module exit path. According to the kernel documentation, destroy_workqueue() expects that all work items have already completed: "Safely destroy a workqueue. All work currently pending will be done first." This change adds an explicit call to flush_workqueue() in the module exit function to ensure no work handler remains in progress or pending at the time of destruction.
1 parent 2588783 commit 7575cf0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

examples/sched.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ static int __init sched_init(void)
2727

2828
static void __exit sched_exit(void)
2929
{
30+
flush_workqueue(queue);
3031
destroy_workqueue(queue);
32+
pr_info("workqueue destroyed\n");
3133
}
3234

3335
module_init(sched_init);

0 commit comments

Comments
 (0)