This function ensures that an appropriate event-handling function is called to handle all pending events from: a window system (where applicable), other tasks (interprocess communication messages), timers, or signals. Upon completion, flush_events causes the program to exit.