Pushing events from sighandlers

I am writing a simulator using SDL, one item that I was planning on
adding was to be able to pause the simulation by an interrupt (^C) in
the console in order to access a built in debugger.

Now, in order to do this properly I would like to post a custom pause
event from the sig handler. SDL_PushEvent is supposed to be thread
safe, though this does not mean that it is safe to call it from a sig-
handler.

Is SDL_PushEvent also safe to call from a sig handler, and if not, do
anyone have a good idea of how to do something like this?

Is SDL_PushEvent also safe to call from a sig handler, and if not, do
anyone have a good idea of how to do something like this?

Yes. In fact, SDL does this for SIGINT and SIGTERM by default…it sends
an SDL_QUIT event internally with SDL_PushEvent() so killing an
application “the unix way” gets translated into roughly a GUI event.

SDL will install its own signal handlers only if the current ones are
SIG_DFL, so it’s safe to set up your own signal handlers before or after
calling SDL_Init() if you want to do this.

That being said, are you really sure you want to do this? the CTRL-C has
to be done in the terminal running the application…if the SDL window
has the keyboard focus, you’ll just get keypress events for CTRL and 'C’
and no signal will be generated. It might be better to just catch
legitimate SDL keyboard events instead of generating your own in this case.

–ryan.