Han XIAO
Han XIAO

Reputation: 1248

What happens if you signal (os signal, not pthread_mutex_unlock) on process blocked on pthread_mutex_wait

What baffles me is that pthread_mutex_lock does not have E_INTR as return value. Although pthread_cond_wait can be spurious waken up and return 0, because of the while loop and Mesa monitor semantics, this is not a problem.

So if a process is blocked by pthread_mutex_lock, and you send a signal to wake it up, after signal handler is executed, what will happen? Are there any mechanism to avoid this spurious wake up?

Upvotes: 0

Views: 46

Answers (1)

Employed Russian
Employed Russian

Reputation: 213646

if a process is blocked by pthread_mutex_lock, and you send a signal to wake it up, after signal handler is executed, what will happen?

If the signal handler didn't invoke any async-signal unsafe operations, then after the handler returns, the process will continue waiting for the mutex.

If the signal handler did invoke an async-signal unsafe operation (e.g. unlocked the mutex), the behavior is undefined: anything can happen, including (but not limited to) crashing, blocking forever, appearing work "normally", etc. etc.

Upvotes: 1

Related Questions