gary-rowe / hid4java

A cross-platform Java Native Access (JNA) wrapper for the libusb/hidapi library. Works out of the box on Windows/Mac/Linux.
MIT License
229 stars 71 forks source link

macOS API calls must be thread safe #152

Open tresf opened 4 months ago

tresf commented 4 months ago

Per hidapi, macOS HID API calls MUST be executed on the same thread to be safe:

Currently, separate threads interacting with a HID devices on macOS, the entire JVM will crash. This can actually be caused by same-thread execution due to this automatic shutdown hook.

https://github.com/gary-rowe/hid4java/blob/672f0a7adaeac0ae9ead2cca32548ed0974886c6/src/main/java/org/hid4java/HidServices.java#L90-L99

Despite this being an upstream issue, Java has some ways of thread pooling so that we can manage this downstream until upstream has a permanent fix.

@Vzor- will be submitting a PR which references this issue with a proposed downstream threading solution.