Fundamental API question - threads or polls

C, C++, and Visual C++
Fresh meat
Posts: 1
Joined: Wed Sep 12, 2018 2:53 pm

Fundamental API question - threads or polls

Postby relavak » Wed Sep 12, 2018 5:35 pm

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.

User avatar
Lead Developer
Posts: 3201
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada

Re: Fundamental API question - threads or polls

Postby Patrick » Thu Sep 13, 2018 10:34 am

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.


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest