hid_close will close immediately on win32#41
hid_close will close immediately on win32#41LianYangCn wants to merge 1 commit intolibusb:masterfrom LianYangCn:master
Conversation
see signal11/hidapi#416 In multi-thread environment, if the hid_read thread is different from the hid_close thread, the hid_read function will block the thread exiting, at the wait object operation. This fix just set the event, after cancel io, so that, hid_read not wait anymore and exiting read
|
maybe this fixes one issue, but there still others, that you'll have in the same scenario, and this fix is not sufficient: what you're trying to fix: what you expect after your fix: Line 712 in e739dc1 what can actually happen: Line 719 in e739dc1 HIDAPI Windows implementation does not support calling hid_read/hid_write and hid_close from multiple threads mainly because it wasn't designed in the right way at the first place if you need to use
|
|
will update README eventually: #45 |
|
@Youw I think this is not a feature, but more like a bug.
Line 825 in e739dc1 and, And if a thread already waiting a hEvent in OVERLAPPED structure, and this will cause Line 708 in e739dc1 hang forever. Calling CancelSynchronousIo is not a bad idea even with synchronous. This PR make sure resource are free. BTW, This IS what actually happen. |
please do not mistaken a bug with a documented (not yet) API limitation. Now, the quote:
If you pay enough attention, the read operation is issued by a
I'm sure it is what actually happens most of the time.
It hides the issue deep in the implementation details and when someone will hit it (with 0.01% chance) - it will take no fun debugging it. |
|
Sorry. I mean this is not a thread related issue, it is about resource release or the state issue. the hEvent may reset by: Line 692 in e739dc1 and on closing, CancelIo does not set it back, hid_close does not set it back neither. Aside from the influence of the thread, setting this hEvent back to the original state, I think it is more reasonable. |
I agree those. |
Set it back to what?
Default object state on creation is Line 158 in e739dc1 NOTE: an Thank you for your PR, but there is no resource leak or a state issue. |
see signal11/hidapi#416
In multi-thread environment, if the hid_read thread is different from the hid_close thread, the hid_read function will block the thread exiting, at the wait object operation.
This fix just set the event, after cancel io, so that, hid_read not wait anymore and exiting read