只给出线程ID,是否有可能从那里决定线程是否仍然存在?我在谈论Linux上的C ++。
答案 0 :(得分:5)
从联系手册:
说明
The pthread_kill() function shall request that a signal be deliv- ered to the specified thread. As in kill(), if sig is zero, error checking shall be performed but no signal shall actually be sent.
这样:
bool isalive(int threadid)
{
return pthread_kill(threadid, 0) != ESRCH;
}