38142

How can I cancel a blocking call such as select() or read()?

Question:

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 EAGAIN.

Answer2:

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.

Recommend

  • adding numpy arrays of differing shapes
  • XSL-FO Processor for C/C++
  • JQuery Cycle and JSON with JQuery
  • Java Rest call with different user certs
  • Creating Word or XML document with VBA
  • Cannot connect to mongodb after app deploys on google app engine
  • Wrong state in Server Controls with same ID's when dynamically adding UserControl to UpdatePane
  • Hive Metastore is not creating MYSQL or Derby Connection
  • Retrieving saved checkboxes' name and values from database
  • Passing value from one component to other component using Input property when using router-outlet
  • Using Facebook Graph API with ASP.NET
  • Alternative to bcrypt when saving passwords in PHP 5.2
  • List using with references, changes behavior when used as a member
  • remove date from DateTimePicker for Compact Framework
  • ggplot2 facet_grid with distinct x-axis labels using facet_grid
  • Python tk scrollbar becomes inactive once text is outside the screen
  • Handle query parameters recursively using htaccess
  • Hide legend for a single geom in ggplot2
  • watir webdriver - window not found
  • Was there ever a proposal to include the URL fragment into the HTTP request?
  • How to put an object in the air?
  • Scripting Support For Image Filtering in DigitalMicrograph
  • Bison does not appear to recognize C string literals appropriately
  • Adding native code to an existing Worklight hybrid app
  • Request Access Token in Postman for Azure Function App protected by Azure AD B2C
  • Reload Page with Javascript after Database changes
  • Creating 2d platforms using JavaScript
  • how to read to huge file into buffer
  • How to write seo friendly url's using htaccess?
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • How to configure the APNS.Certificate in the arm template
  • Geokit in Ruby on Rails, problem with acts_as_mappable
  • How to include associated objects using gon in Rails/jQuery
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs
  • How can I ssh into a server that requires 2 password authentication using python's paramiko mod
  • How to decleare char *const argv[] in swift [duplicate]
  • Background transfer download task failed when app was closed
  • XEP-0166: Jingle protocol implementation for voice/video chat in iOS
  • Android Library Projects on Windows and Mac
  • How to check if object is null in Java?