Page 1 of 1

Are Event handlers blocking/done serially?

Posted: Thu Jul 21, 2022 11:18 am
by Rhybot
I use a VoltageInput Phidget to read from a flow sensor, and update a running-integration of total flow upon each new VoltageChange event. This is accomplished with the awesome VoltageChange Event system.

My question: does a long-running handler block other Events from coming in?

In the Special Considerations section of https://www.phidgets.com/docs/Using_Events, it hints the Events are blocking, but I wanted to confirm as it's never explicitly stated.

Can you confirm an individual Phidget won't send a new Event until the prior handler completes?

For the record, I think a blocking handler is a good thing, because otherwise I would have to make my handler being thread-safe.

Re: Are Event handlers blocking/done serially?

Posted: Wed Jul 27, 2022 10:11 am
by Patrick
The library will creates a pool of event dispatch threads - but all of the events for a particular channel come from the same thread. If you are using multiple channels, you will need to consider that events from each channel may be delivered from different threads.

If you block an event for too long, this will cause issues - the library has an internal queue to hold up to 200 events, so you must be careful not to block longer that 200 * the data interval, or events will start to get dropped.

-Patrick

Re: Are Event handlers blocking/done serially?

Posted: Wed Jul 27, 2022 12:34 pm
by Rhybot
Okay thank you for the response!

> all of the events for a particular channel come from the same thread.

> If you are using multiple channels, you will need to consider that events from each channel may be delivered from different threads.

Both of these make sense and embodies a desirable implementation, thank you!

> the library has an internal queue to hold up to 200 events, so you must be careful not to block longer that 200 * the data interval

Is this internal queue on a per-channel basis, or system-wide? I have a whole complex system controlled with ~120 Phidget channels, of many different Phidget APIs. Most are DigitalOutput API though.

Re: Are Event handlers blocking/done serially?

Posted: Thu Jul 28, 2022 10:51 am
by Patrick
The queue is per-channel.

-Patrick

Re: Are Event handlers blocking/done serially?

Posted: Thu Jul 28, 2022 2:52 pm
by Rhybot
Thank you and sounds good!