Skip to content
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

thread safe? #45

Open
dsula opened this issue Mar 10, 2012 · 5 comments
Open

thread safe? #45

dsula opened this issue Mar 10, 2012 · 5 comments

Comments

@dsula
Copy link

dsula commented Mar 10, 2012

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.

@signal11
Copy link
Owner

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.

@dsula
Copy link
Author

dsula commented Mar 10, 2012

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?

@signal11
Copy link
Owner

I think that should be fine.

@michalmmm
Copy link

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.

@signal11
Copy link
Owner

signal11 commented Sep 4, 2013

More than that would need to be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants