Threading with Phidget 2.2 API
Posted: Tue Jun 23, 2020 12:05 pm
Question: Are The Phidget 2.2 API handles threadsafe? Can phidget calls (other than create/open/close/delete) be made on the same handle from multiple threads at the same time? or does the application itself need to mutex calls for the same handle or does the application need to mutex ALL calls into the API?
With the Phidget 2.1 API, the library worked in multiple threads by having each thread own its own handle to the same channels. e.g. My C++ code under windows could open two different handles to the same Interfacekit. One thread could monitor inputs and set/clear output channels. A user controlled dialog in a main U/I thread could monitor and display current states of input/output channels.
With the 2.2 API, the ability to open a channel multiple times is specifically disallowed (documented here: https://www.phidgets.com/docs/Attaching_a_Channel) Attempting to attach to the same channel a second time seems to wait indefinitely and timeout. Also, opening a channel clears its state back to 0, so it doesn't seem possible to just open an output channel to read its current or last set state anyway as you always get 0 for a newly opened channel.
With the Phidget 2.1 API, the library worked in multiple threads by having each thread own its own handle to the same channels. e.g. My C++ code under windows could open two different handles to the same Interfacekit. One thread could monitor inputs and set/clear output channels. A user controlled dialog in a main U/I thread could monitor and display current states of input/output channels.
With the 2.2 API, the ability to open a channel multiple times is specifically disallowed (documented here: https://www.phidgets.com/docs/Attaching_a_Channel) Attempting to attach to the same channel a second time seems to wait indefinitely and timeout. Also, opening a channel clears its state back to 0, so it doesn't seem possible to just open an output channel to read its current or last set state anyway as you always get 0 for a newly opened channel.