仅给定线程 ID,是否可以从那里决定线程是否仍然存在?我说的是 Linux 上的 C++。
最佳答案
来自手册页:
DESCRIPTION
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;
}
关于c++ - 给定一个线程 id,如何在 linux 上的 C++ 中确定它是否存活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8126555/