Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ usleep是否创建线程取消点?_C++_Linux_Pthreads - Fatal编程技术网

C++ usleep是否创建线程取消点?

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);

根据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;
sPOSIX规范中提供了取消点和可选取消点的完整列表:


usleep()
是一个强制取消点

我在Mac OS上的Instrument.app中看到了调用
pthread\u testcanel
函数的调用树


但是usleep似乎没有。

+1:几乎正是我要说的。这里有一个替代URL(后来的标准)用于相同的信息。