-
Notifications
You must be signed in to change notification settings - Fork 901
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
Mac OS X backend not thread safe #95
Comments
hid_init() and hid_exit() are designed to be called at program startup and shutdown, respectively, to initialize the library. Two threads shouldn't be doing sequences of hid_init() ... hid_exit(). They only need to call hid_open*()/hid_close(). It could be beneficial to add what you're saying, but this can easily be worked around right now by using hid_init() as intended (above). |
In my case HIDAPI is used in a library in charge of the HID devices enumeration. This library is then used by other libraries (with no knowledge of HIDAPI). The final application can be a browser like Firefox so I cannot use hid_init() and hid_exit() at the application startup and shutdown. A long term strategy would be to use contexts managed by hid_init() and hid_exit() and used by the other hidapi calls. No need to fix the problem right now. I have a workaround that works for me. |
The Mac OS X backend uses a static variable
static IOHIDManagerRef hid_mgr = 0x0;
The problem occurs with two threads are doing the sequence
hid_init()
[...]hid_exit()
The first thread to call
hid_exit()
will releasehid_mgr
and then the second thread will have problems.For example I have a crash in
hid_enumerate()
on line:CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
because
hid_mgr
has been reset toNULL
.My workaround is to NOT call
hid_exit()
sohid_mgr
is not released.A proper solution would be to add a counter of use and really release
hid_mgr
when no other thread is using HIDAPI anymore.The text was updated successfully, but these errors were encountered: