pthreads - Determine whether a thread is blocked -
does know of way determine whether thread blocking? basically, want check whether thread blocking (in case on af_unix datagram socket receive call) , send signal interrupt if is.
i'm working on linux using boost.thread meaning underneath i'm using pthreads. system has nptl.
i think answer "no", want see if i'm missing something.
this not possible (it possible using functionality intended debuggers, neither simple, portable or safe).
you not want anyway, because such use have inherent race condition. may check if thread blocking before block (in case miss waking it), or may stop blocking after find blocking.
the usual method solve problem "self-pipe trick":
- create pipe
pipe()
; - the target thread, instead of blocking in
recvfrom()
, blocks inpoll()
orselect()
. file descriptors monitor include datagram socket , read end of pipe. - to wake target thread, other thread writes single byte write end of pipe.
(the recvfrom()
should changed use msg_dontwait
flag, since never want block here, , block in poll()
/ select()
instead).
Comments
Post a Comment