thr_suspend(3C) 可用来立即暂停执行 target_thread 所指定的线程。如果从 thr_suspend() 成功返回,则将不再执行暂停的线程。
因为 thr_suspend() 在暂停目标线程时不会考虑该线程可能持有的锁,所以,在使用 thr_suspend() 时一定要格外小心。如果要暂停的线程调用的函数需要由已暂停的目标线程拥有的锁,则将产生死锁。
#include <thread.h> int thr_suspend(thread_t tid);
线程暂停之后,以后调用 thr_suspend() 将不起任何作用。信号无法唤醒暂停的线程。线程恢复执行之前,信号将一直保持暂挂状态。
在以下概要中,pthread 中定义的 pthread_t
tid 与 Solaris 线程中定义的 thread_t
tid 相同。这两个 tid 值可以通过赋值或通过使用强制转换来互换使用。
thread_t tid; /* tid from thr_create() */ /* pthreads equivalent of Solaris tid from thread created */ /* with pthread_create() */ pthread_t ptid; int ret; ret = thr_suspend(tid); /* using pthreads ID variable with a cast */ ret = thr_suspend((thread_t) ptid);
thr_suspend() 在成功完成之后返回零。其他任何返回值都表示出现了错误。如果出现以下情况,thr_suspend() 将失败并返回对应的值。
ESRCH
描述:当前的进程中找不到 tid。