Fix for crash

I came up with a fix for the APE-related crash I found a few days ago. It seems that signals can be delivered to any active thread. If you have APE installed, it injects its own thread into the application. If the signal happens to be sent to APE’s thread, there’s a chance bad things might happen.

The fix was for my signal handler to make sure it’s running in the thread we want, and if it isn’t, I send the signal to the proper thread and don’t do anything else.

void MySignalHandler(int SigNum)
	if (!pthread_equal(_my_signal_thread,pthread_self()))
 ... etc ...

Elsewhere, I save a reference to the desired thread when I install the signal handlers:

main(int argc, char **argv)
	_my_signal_thread = pthread_self();
	signal(SIGIO, MySignalHandler);
 ... etc ...

Comments are closed.