C pthead_创建导致错误状态0x7F00
我正在尝试在我的Windows 10 64位计算机上运行pthread示例 我正在使用最新版本的cygwin(64位)进行编译,将代码编译为C pthead_创建导致错误状态0x7F00,c,gcc,cygwin,pthreads,C,Gcc,Cygwin,Pthreads,我正在尝试在我的Windows 10 64位计算机上运行pthread示例 我正在使用最新版本的cygwin(64位)进行编译,将代码编译为 gcc thread.c -pthread -o main.exe 编译时没有错误。thread.c看起来是这样的: #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <s
gcc thread.c -pthread -o main.exe
编译时没有错误。thread.c看起来是这样的:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
void *worker_thread(void *arg)
{
printf("This is worker_thread()\n");
pthread_exit(NULL);
}
int main()
{
int a = fork();
if (a == 0) {
printf("child a=%d\n", a);
pthread_t my_thread;
int ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
printf("ret = %d\n", ret);
} else {
printf("parent a=%d\n", a);
int status;
wait(&status);
printf("status = 0x%X (%d)\n", status, status);
}
return 0;
}
parent a=10868
child a=0
status = 0x7F00 (32512)
这是因为pthread_create导致我的代码退出
根据,该错误意味着:
“它没有因为信号而死亡,也没有产生内核转储,它以代码127(0x7F)退出
127的含义尚不清楚,这就是为什么它应该附带一条错误消息。”
在我的windows 8 64位计算机上,代码按预期运行,安装了相同版本的cygwin(64位),并返回此输出
parent a=26744
child a=0
ret = 0
this is worker_thread()
status 0x0 (0)
任何帮助都将不胜感激。Win10 64位/Cygwin 64位--按预期运行。好吧,至少这不是操作系统的问题,可能您没有在创建的线程上加入或分离,这是未定义的行为(我假设您在这种情况下希望加入它)。尝试添加
pthread\u-join(my\u-thread,NULL)创建线程后,查看发生了什么。在pthread\u create
调用后,子线程不进行处理,将无法到达的内容放入其中,因为子线程会自动崩溃。