Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.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 pthead_创建导致错误状态0x7F00_C_Gcc_Cygwin_Pthreads - Fatal编程技术网

C pthead_创建导致错误状态0x7F00

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

我正在尝试在我的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 <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
调用后,子线程不进行处理,将无法到达的内容放入其中,因为子线程会自动崩溃。