Open dsula opened 12 years ago
The Windows implementation is not entirely thread safe. There should not be a problem connecting on the main thread and then reading/writing on a separate thread though.
Alan.
Ok, I found the problem to be in fact an issue in the device firmware. However I still wonder, what do you mean by the windows version is not entierly safe? I have 1 thread constantly running hid_enumerate to dynamically manage device connect/disconnect. Device IO is done by other threads. Do you see a potential problem with this?
I think that should be fine.
Windows implementation is not thread-safe at all.
Simply because (but not only) register_error function is not thread safe and that function is actually called from almost everywhere in hid.c.
To resolve it the following block would have be made thread safe: LocalFree(device->last_error_str); device->last_error_str = msg; otherwise LocalFree function could be called more than once and would fail when called for the second time.
More than that would need to be changed.
WINDOWS I'm having problems when running hid_enumerate and hid_read/hid_write in different threads. I'm not sure if hidapi is supposed to be thread safe and the problem is in fact in my firmware device code, or if this is hidapi that's the problem.
Sooner or later my host code doesn't work anymore as the hid_read/hid_write fail and this only happens while a 2nd thread using hid_enumerate is active.