小编use*_*788的帖子

从main调用pthread_exit可以吗?

当我打电话pthread_exitmain,程序永远不会终止.我期望程序完成,因为我退出程序的唯一线程,但它不起作用.好像挂了.

#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.2pthreads-win32 v2.8.0.0(链接libpthreadGC2.a).

该库似乎是确定(例如,呼叫pthread_selfpthread_createmain正常工作).

是否有什么我不应该调用任何理由pthread_exitmain

c winapi program-entry-point pthreads exit

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

exit ×1

program-entry-point ×1

pthreads ×1

winapi ×1