flush_workqueue 简介

flush_workqueue 是 Linux 内核中用于同步工作队列(workqueue)任务的一个函数。它的主要作用是阻塞当前调用者,直到指定工作队列中的所有已排队任务都被执行完毕。调用时,新的任务即使被加入队列,也不会影响当前的等待,只有在 flush_workqueue 调用时已经存在于队列中的任务会被等待执行完[2][4][6]。

常见用法场景包括模块卸载、驱动关闭等场合,确保所有异步任务都已完成,避免资源冲突或内存泄漏[6]。

简单示例:

void flush_workqueue(struct workqueue_struct *wq);
// 阻塞直到 wq 队列中的所有任务都执行完毕

与之类似,flush_work 用于等待单个 work 完成,而 flush_workqueue 是针对整个工作队列[1][2][5]。

Citations:
[1] https://blog.csdn.net/Ivan804638781/article/details/115700572
[2] https://blog.csdn.net/gtopia/article/details/10207467
[3] https://www.cnblogs.com/wwang/archive/2010/10/27/1862202.html
[4] https://www.binss.me/blog/analysis-of-linux-workqueue/
[5] https://www.cnblogs.com/myriel/p/17588205.html
[6] https://github.com/apachecn/apachecn-linux-zh/blob/master/docs/linux-device-driver-dev/03.md
[7] https://e-mailky.github.io/2016-10-14-linux_kernel_api2
[8] http://www.360doc.com/content/10/0716/11/496343_39374303.shtml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值