ofEvents and threads

Hi all,
I have a threaded callback function that gives a boolean to the main application. The threaded function may run at 500 fps, but the speed is variable, and the main app will run at about 30 fps, also variable. I want to throw an event (one or more than one depending on user’s choice) every time the boolean is true, and it may be true anytime.

The question is:
Not sure if it would be better to throw only one single event with a count of highs and lows, or if I should use multiple ofEvents instead?

Next question would be what would happen if I register multiple callbacks like that one? is the order of the events being kept on the queue of ofEvents even if they run on different threads?

Any suggestions?

the order of events is kept as they were registered or if you specify a priority by their priority. take into account though that the event call will happen in the same thread it’s notified so you would need to lock any data structure you are going to modify while in the listener call.

an easier and probably more efficient way to do this would be to use a thread channel to send the bools then in the main thread use tryReceive in a loop to get all of them:

bool flag;

if you only need the number of times there’s false or trues then accumulating them and returning them through a method that properly locks the involved variables might be most efficient

1 Like

Thank you very much! this is a very important bit of info to take into account!
Also will look into ofThreadChannel.