On 10/07/2013 05:43 PM, Renato Forti wrote:
05) Boost.Application Resources
[Other Boost.Application Resources]
* Download Last Version https://sourceforge.net/projects/boostapp/
Your POSIX signal handler (common_application_imp::sighandler) ends up calling a boost::function provided by the user. In other words, the user callback is executed from the signal handler. This is problematic because it is very limited what you are allowed to do in a signal handler, and your users should not be required to handle those restrictions. In fact, your examples violate those restrictions. Briefly put, you cannot use any function that may allocate memory, because most memory managers are not designed to be reentrant. POSIX lists exactly which system calls are allowed. Look for 'async-signal- safe' in: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html A common workaround is to create a pipe (e.g. with the pipe(2) system call) and let the application and the signal handler interact via that pipe, because the write(2) system call is async-signal-safe (but note that fwrite, or any other buffered variant are not safe.) Usually, the signal handler will simply send a single byte per signal to the application. On another note, I suggest that you use sigaction() instead of signal() to install signal handlers.