Joe
Joe

Reputation: 7798

Is a signal caught if a thread is waiting on a mutex?

I have a thread blocked on a mutex. The application also has custom signal handlers, set using sigaction. If the thread that receives a catchable signal is blocked on a mutex, will the signal handler be called, or will it be blocked until the mutex is released?

Upvotes: 4

Views: 807

Answers (1)

Slava
Slava

Reputation: 44258

Most probably it will depend on implementation, in pthread for example signal handler will be executed and then thread will wait for mutex upon handler return:

man pthread_mutex_lock

If a signal is delivered to a thread waiting for a mutex, upon return from the signal handler the thread shall resume waiting for the mutex as if it was not interrupted.

Upvotes: 7

Related Questions