WaitableEvents

Hello

I was wondering if i could get a bit more information on WaitableEvents? Currently i’m using them to sync a recording to a metronome, so that way the recording is always a number of bars length. I have a record function that is activated when the record button is pressed and this then waits on a waitableEvent until the metronome signals the event at the start of a bar and this all works fine. However is it possible to have multiple functions waiting on a single waitableEvent, because at the moment if i try to activate 2 of these record functions the first one will activate at the start of the bar and the second one will wait until the start of the next bar.

On a side note i’m changing the colour of the record button while it waits to activate and this worked fine while the code was placed in a thread. However as it wasn’t necessary for the code to be in a thread i moved it to a function. The waitableEvents still work fine but the colour updates don’t work. I’m using a actionBroadcaster to update the colour. Is there any reason for this?

Thank you

Waitable event are atomic.
This means that when someone signal an event, if there is multiple waiter, only one will be waken up and reset the event.
That’s true, only if not build in manual reset mode.

In manual reset mode (constructor argument set to true), then when a waiter is waken up (or at least one of them), must reset the event before it can be waited upon again, else, any waiter calling event.wait() will succeed immediately.

Thanks

So i can’t really have both of them activating at the same time. I guess i’ll have a single thread that waits on a waitable event and then triggers any record functions that the user has activated.

[quote=“joeBaker”]
So i can’t really have both of them activating at the same time.[/quote]
Not sure I understand your remark. If you set your event to manual reset, then, when one of your thread calls “event.signal()”, and you have two other thread waiting on “event.wait()”, then both thread will wake up (not necessary at the same time).
Then, if it happens that one thread does “event.reset()” before the second thread got waken up, this second thread will not wake up.
Up to you to ensure the order of waking up / reseting the events.

Alright so i just need to check where i’m resetting the event in my code and that way they should activate almost simultaneously.

Thanks again