C++ usleep是否创建线程取消点?
根据Linux手册页,只有以下函数是线程取消点:pthread_join、pthread_cond_wait、pthread_cond_timedwait、pthread_testcancel、sem_wait、sigwait。在我的测试程序中,线程在usleep上退出。线程函数: void* ThreadFunction(void* arg) { int n = 0; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); for(;;) { ostringstream s; s << "Thread iteration " << n++; PrintLine(s.str().c_str()); usleep(500000); PrintLine("Check whether thread canceled..."); pthread_testcancel(); PrintLine("Thread is not canceled - continue"); } pthread_exit(NULL); } void*ThreadFunction(void*arg) { int n=0; pthread_setcancelstate(pthread_CANCEL_ENABLE,NULL); pthread_setcanceltype(pthread_CANCEL_DEFERRED,NULL); 对于(;;) { Ostringstreams;C++ usleep是否创建线程取消点?,c++,linux,pthreads,C++,Linux,Pthreads,根据Linux手册页,只有以下函数是线程取消点:pthread_join、pthread_cond_wait、pthread_cond_timedwait、pthread_testcancel、sem_wait、sigwait。在我的测试程序中,线程在usleep上退出。线程函数: void* ThreadFunction(void* arg) { int n = 0; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sPOSIX规范中提供了取消点和可选取消点的完整列表:
usleep()
是一个强制取消点我在Mac OS上的Instrument.app中看到了调用pthread\u testcanel
函数的调用树
但是usleep似乎没有。+1:几乎正是我要说的。这里有一个替代URL(后来的标准)用于相同的信息。