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

Documentation: add multi-threading notes #45

Open
Youw opened this issue Jul 13, 2019 · 13 comments
Open

Documentation: add multi-threading notes #45

Youw opened this issue Jul 13, 2019 · 13 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Youw
Copy link
Member

Youw commented Jul 13, 2019

need add notes to README regarding multithreading, e.g. regarding Windows issues/non-full support
maybe some more

@Youw
Copy link
Member Author

Youw commented Jan 26, 2021

NOTE for everyone: hidapi not thread-safe in general, with a few platform-specific/usage-spacific exceptions.

Damn, I need to get my hands to describe everything in details.

@mcuee
Copy link
Member

mcuee commented Jun 15, 2021

Reference: Windows: unable to interrupt blocking hid_read call #133

@Youw Youw added this to To do in v0.13 Release Sep 18, 2021
@Youw Youw unpinned this issue Mar 16, 2022
@Youw Youw pinned this issue Mar 16, 2022
@Youw Youw unpinned this issue May 16, 2022
@Youw Youw pinned this issue May 16, 2022
@Qbicz Qbicz unpinned this issue Oct 13, 2022
@Qbicz Qbicz pinned this issue Oct 13, 2022
@mcuee
Copy link
Member

mcuee commented Oct 30, 2022

I see this and #133 are tied to 0.13.0 milestone. Supposedly this one will "help" #133, right?

Any activities on this one?

#146 is supposed to fix #133, but I see no activities there.

@mcuee
Copy link
Member

mcuee commented Oct 30, 2022

@Youw
Just wondering what is the plan for 0.13.0 release, say as a Christmas gift. :-)

@Youw
Copy link
Member Author

Youw commented Oct 30, 2022

0.13 already includes a lot of good improvements, so I guess making a release (before Christmas) would be a good thing regardless if it is going to include the multithreaded documentation/fixes or not

@mcuee
Copy link
Member

mcuee commented Oct 30, 2022

0.13 already includes a lot of good improvements, so I guess making a release (before Christmas) would be a good thing regardless if it is going to include the multithreaded documentation/fixes or not

I agree. Thanks.

@mcuee
Copy link
Member

mcuee commented Jan 6, 2023

@Youw

It is great that you have released hidapi 0.13. Thanks.

@mcuee
Copy link
Member

mcuee commented May 10, 2023

Reference by Youw.

As for multithreaded usage of hidapi - many projects successfully using a separate thread for hid_read/_timeout, and another thread for read/everything else.

@mcuee
Copy link
Member

mcuee commented May 10, 2023

Another reference by Youw.

client code should first stop any read/write attempts before trying to close the device as hid_close cannot not be thread-safe by design, even it it is sometime, for some implementations.

@mcuee
Copy link
Member

mcuee commented May 10, 2023

Add a stub FAQ entry here.
https://github.com/libusb/hidapi/wiki#faq

@mcuee
Copy link
Member

mcuee commented May 11, 2023

Comments by Youw here.

Oh yes, HIDAPI on macOS has an additional issue regarding thread-safety. I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. Looks like on macOS hid_init/hid_exit needs to be called in the same thread, which is an additional restriction compared to other platforms.

@mcuee
Copy link
Member

mcuee commented May 14, 2023

Reference from node-hid.
https://github.com/node-hid/node-hid#thread-safety-worker-threads-context-aware-modules

Thread safety, Worker threads, Context-aware modules
In general node-hid is not thread-safe because the underlying C-library it wraps (hidapi) is not thread-safe. However, node-hid is now reporting as minimally Context Aware to allow use in Electron v9+. Until node-hid (or hidapi) is rewritten to be thread-safe, please constrain all accesses to it via a single thread.

@k1-801
Copy link

k1-801 commented Mar 11, 2024

Oh yes, HIDAPI on macOS has an additional issue regarding thread-safety. I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. Looks like on macOS hid_init/hid_exit needs to be called in the same thread, which is an additional restriction compared to other platforms.

I have a potential solution, described fully in #666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
No open projects
Development

No branches or pull requests

3 participants