Its been answered, but I thought I would add a little more background.
yes, events run in their own thread, they are also not re-entrant so while you are in the thread it will not fire again.
On V5, we have enough resources so that every event has a dedicated thread, however, on IQ and EXP we use what is known as a thread pool. When an event is triggered an available thread is found in the thread pool and assigned to that event to run the callback function. The size of the thread pool varies by platform.
On IQ generation 1 it’s 4 threads (as we have very little memory)
On IQ generation 2 it’s 8 threads.
On EXP it’s 10 threads
This limits the number of simultaneous event handlers that can be running not the number of event handlers that can be registered, on IQ gen 1 you can still have 64 (IIRC) events registered, but only 4 can run at any given time.
Most event handlers should not block, run the required action and then leave the callback. On V5 if an event handler does block, it’s not really a problem, but you can see that on IQ gen 1 it could cause issues.
For simple event handlers I like to use lambda functions, for example.
vex::controller c1;
vex::pneumatic pnu(PORT7);
int main() {
c1.ButtonRUp.pressed( [](){
pnu.extend( cylinderAll );
} );
c1.ButtonRUp.released( [](){
pnu.retract( cylinderAll );
} );
// more code
}
and yes, that’s the API for the IQ pneumatics shown there.
Using Python, you can also pass parameters to an event handler, for example.
def screen_press(name):
print("Screen pressed " + name)
brain.screen.clear_screen(vex.Color.GREEN)
def screen_release():
print("Screen released")
brain.screen.clear_screen(vex.Color.BLACK)
E1 = brain.screen.pressed(screen_press, ("hello",))
E2 = brain.screen.released(screen_release)
parameters are passed as a tuple