-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement thread-safe variant of handle_events #154
Conversation
How does this differ from what the call to In the code I wrote as a precursor to #143, the reason for reimplementing |
Apparently, I didn't read Multi-threaded applications and asynchronous I/O carefully enough and missed the part that says There seems to be a weird quirk in libusb where the documentation states: "If a zero timeval is passed, this function will handle any already-pending events and then immediately return in non-blocking style.", but yet if I pass a zero timeval, the function does not handle any events. It requires some non-zero timeout for it to make actual progress.
The motivation to use I guess that I can either use |
If you're trying to use it non-blocking, the |
Is it possible that the 1ms timeout is just giving it time to complete within the first call to |
Thank you for the very insightful comments!
Yes, it looks like you are right. I removed this part from the
With a background thread blocking on handling events, I probably need something similar anyway if I want to be able to quit the thread gracefully and call |
I am closing this PR, since it looks like my current two pull requests to merge an asynchronous API for rusb do not need this bit at all. |
This is the first PR split off from PR #153 that focuses on implementing a thread-safe version of
handle_events()
as outlined in the libusb documentation, but also it is based on the code in PR #143 with some fixes to make sure it always makes progress, even if the timeout it is 0.libusb seems to require a timeout of at least 1ms to make any progress, so we ensure that the timeout is always at least 1ms when calling into libusb. Other than that we rely on
loop
andif
to implement a do while loop, such that the code is executed at least once.