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.Answer1:
The traditional way of interrupting
select(2) is the <a href="http://cr.yp.to/docs/selfpipe.html" rel="nofollow"><strong>
self-pipe trick</strong></a>. The input/output calls are better served by having the descriptors <em>non-blocking</em> and handling
In these situations you should probably use a small or immediate timeout and have additional logic that handles when/how/why the next select/read attempt is made.