多进程机制术语-Polling

本文介绍了轮询(Polling)的概念及其在并发程序中的应用。轮询是一种不断检查资源是否可用的方法,通常通过非阻塞调用实现。然而,轮询会浪费处理器时间,更好的方法是设置事件并等待资源可用时触发。文章还讨论了如何选择阻塞或立即返回的选项以适应不同的编程需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  Polling (see also spin-waiting) is testing for the availability of a resource by repeatedly requesting the resource via a non-blocking call, until the resource becomes available. Polling is wasteful of processor time that could be used by another thread of control in a concurrent program. Unless the resource is likely to become available almost instantaneously, a better approach is to have the resource set an event when it becomes available, and block awaiting the event.

The is-resource-available function for many common resources has an option either to block or to return immediately. The first option is used in simple programs that are typically single threads of control. The second option facilitates polling, but it also supports blocking on a binary semaphore, then accessing the resource multiple times until the resource is exhausted.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值