当我打电话pthread_exit
时main
,程序永远不会终止.我期望程序完成,因为我退出程序的唯一线程,但它不起作用.好像挂了.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int main(int argc, char *argv[])
{
printf("-one-\n");
pthread_exit(NULL);
printf("-two-\n");
}
Run Code Online (Sandbox Code Playgroud)
Process Explorer显示(仅)线程处于Wait:DelayExecution
状态.
根据pthread_exit
文件:
在最后一个线程终止后,进程将以退出状态0退出.行为应该就像实现在线程终止时调用带有零参数的exit()一样.
我正在使用Dev-C++ v4.9.9.2和pthreads-win32 v2.8.0.0(链接libpthreadGC2.a
).
该库似乎是确定(例如,呼叫pthread_self
或pthread_create
从main
正常工作).
是否有什么我不应该调用任何理由pthread_exit
从main
?