Page 1 of 1

Fundamental API question - threads or polls

Posted: Wed Sep 12, 2018 5:35 pm
by relavak
It is unclear from the documentation how the phidget22 library handles synchronization between a main loop and the phidget operations. Does the library use a separate thread or multiple threads? If so, how do I synchronize my main loop with the library to avoid race conditions (i.e. what are the design rules and api related to locking). If not a thread, when are phidget operations such as attach and detach called?

One other issue is that sometimes my calls to setdutycycle fail with the error code "unexpected". This doesn't seem to invoke the detach but subsequent calls to setdutycycle also fail and forcing an attach seems to cause a bunch of detach/attach cycles that eventually look like they cause massive failure. The error handler also does not seem to be called.

Re: Fundamental API question - threads or polls

Posted: Thu Sep 13, 2018 10:34 am
by Patrick
The Phidget API is fully thread-safe.

Event are called from a pool of threads, it is up to the user to synchronize event calls.

Call into the library are mostly synchronous. The exceptions are open() (without the timeout) and the _async() versions of some set functions.


Can you provide some more info about your failure case:
Are you using the latest library?
What hardware are you using?
Please provide a library log of the failure at INFO level.

-Patrick