如何取消阻塞调用,例如select()或read()? [英] How can I cancel a blocking call such as select() or read()?

查看:312
本文介绍了如何取消阻塞调用,例如select()或read()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,如何取消另一个线程的阻塞调用,如select()或(在串行通讯和类似情况下)read()?解决此类问题的传统方式是什么?我想一个人可以使用一个小的超时时间,这也许可以正常工作,但对我来说似乎有点破烂.

As the title says, how can I cancel a blocking call such as select() or (in the case of serial comm and similar) read() from another thread? What is the traditional way of solving things like this? I suppose one could use a small timeout and that would probably work fine but that seems like a bit of a hack to me.

推荐答案

中断select(2)的传统方法是 self-pipe trick .通过使描述符 non-blocking 和处理EAGAIN更好地服务于输入/输出调用.

The traditional way of interrupting select(2) is the self-pipe trick. The input/output calls are better served by having the descriptors non-blocking and handling EAGAIN.

这篇关于如何取消阻塞调用,例如select()或read()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆