Cancelling a Blocked Pthread
How do I cause a thread to respond to pthread_cancel开发者_如何学JAVA()
if it is blocked on a sem_wait()
?
You can set a signal handler, let's says for SIGUSR1, for the thread that will be blocking then, from another thread, you call pthread_cancel(tid)
and pthread_kill(tid, SIGUSR1)
. The thread will be canceled once sem_wait()
is interrupted by the signal.
精彩评论