Are Event handlers blocking/done serially?

Comments & issues
Post Reply
Rhybot
Phidgeteer!
Posts: 52
Joined: Wed Aug 14, 2019 4:58 pm
Contact:

Are Event handlers blocking/done serially?

Post 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.
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Are Event handlers blocking/done serially?

Post 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
Rhybot
Phidgeteer!
Posts: 52
Joined: Wed Aug 14, 2019 4:58 pm
Contact:

Re: Are Event handlers blocking/done serially?

Post 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.
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Are Event handlers blocking/done serially?

Post by Patrick »

The queue is per-channel.

-Patrick
Rhybot
Phidgeteer!
Posts: 52
Joined: Wed Aug 14, 2019 4:58 pm
Contact:

Re: Are Event handlers blocking/done serially?

Post by Rhybot »

Thank you and sounds good!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 22 guests