multithreading - Terminating multithreaded application in C++11 by POSIX signal -


i wrote simple multithreaded application in c++11 on linux platform , terminate server , running threads sending sigint signal.

obviously server application uses thread support c++11 (std::thread etc.). although found support signal handling in c++11 (std::signal), couldn't find support handling signals in multithreaded environment.

so question - there way how handle signals in multithreaded application in c++11 or have rely on pthreads because application needs deal signals?

2.4 signal concepts:

at time of generation, determination shall made whether signal has been generated process or specific thread within process. signals generated action attributable particular thread, such hardware fault, shall generated thread caused signal generated. signals generated in association process id or process group id or asynchronous event, such terminal activity, shall generated process.

...

signals generated process shall delivered 1 of threads within process in call sigwait() function selecting signal or has not blocked delivery of signal.

in light of above, in multi-threaded process common solution block signals 1 intends handle in threads one. 1 thread handle process signals , tell other threads (e.g. terminate) , main thread. easy block signals in main thread before creating other threads, inherit signal mask of parent thread. once main thread done creating child threads , ready handle signals must unblock those.

unfortunately, c++11 not provide means that. have use posix functions. scroll down signalling in multi-threaded process in pthread_sigmask example creates special signal handling thread. latter not necessary if using event loop in main thread can handle signals, unblock signals before entering event loop.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -