2

Does a signal handler set with sigaction run in its own thread? Can I use Pthreads tools to synchronize my signal handler with my main program, like Pthreads mutexes? Can I use C++11 tools like mutex and atomic?

Sorry if the question is a bit too general but I'm really confused about the relation between signals and threads.

I'm working on Linux but the question applies to UNIX in general.

Yaron Cohen-Tal
  • 2,005
  • 1
  • 15
  • 26
  • See [here](http://stackoverflow.com/questions/12952262/signal-handler-function-in-multithreaded-environment). – Ami Tavory May 23 '15 at 09:09

1 Answers1

1

No.

The only functions you can safely call in signal handlers are async-signal-safe functions. For Linux, you can find a list of such functions in the signal.7 man page, under "Async-signal-safe functions", a bit more than halfway down the page.

Any function not listed as an async-signal-safe can not be safely called in a signal handler.

Note that the only synchronization function listed as async-signal-safe on Linux is sem_post().

Andrew Henle
  • 32,625
  • 3
  • 24
  • 56