为什么';这不管用吗?Windows,使用process.h #包括 #包括 void sayit(void*arg){ printf(“你好,世界!来自子进程\n”); _endthread(); } int main(int argc,字符**argv){ if(_beginthread(sayit,16,NULL)=-1) printf(“错误\n”); 返回0; }

为什么';这不管用吗?Windows,使用process.h #包括 #包括 void sayit(void*arg){ printf(“你好,世界!来自子进程\n”); _endthread(); } int main(int argc,字符**argv){ if(_beginthread(sayit,16,NULL)=-1) printf(“错误\n”); 返回0; },c,windows,C,Windows,根据idea,程序必须在函数中打印字符串,但它不会出现。 是否有任何功能可确定流程是否已完成或仍在运行? 你能给我process.h完整文档的链接吗?你产生了一个线程,但你并不等待它。程序在第二个线程恢复之前结束的可能性非常高。使用具有“连接”功能的_beginthreadex和WaitForSingleObject或Boost.Threads。当以非挂起状态启动线程时,无法保证线程何时启动,因此可能只是程序在线程启动之前或线程启动时结束 为了确保线程运行,您需要执行以下操作 #include

根据idea,程序必须在函数
中打印字符串,但它不会出现。
是否有任何功能可确定流程是否已完成或仍在运行?

你能给我process.h完整文档的链接吗?

你产生了一个线程,但你并不等待它。程序在第二个线程恢复之前结束的可能性非常高。使用具有“连接”功能的_beginthreadex和WaitForSingleObject或Boost.Threads。

当以非挂起状态启动线程时,无法保证线程何时启动,因此可能只是程序在线程启动之前或线程启动时结束

为了确保线程运行,您需要执行以下操作

#include <stdio.h>
#include <process.h>

void sayit(void * arg) {

    printf("hello, world! from child process\n");
    _endthread();

}

int main(int argc, char ** argv) {

    if (_beginthread(sayit, 16, NULL) == -1)
        printf("Error\n");

    return 0;
}

它编译吗?如果不是,错误是什么?请发布错误消息我同意,最好是uint32\u t或其他东西,毕竟他们使用了返回值;-)
unsigned threadID = 0;
HANDLE hd = (HANDLE)_beginthreadex( NULL, 0, sayit, NULL, 0, &threadID);
WaitForSingleObject( hd, INFINITE ); // this will wait for thread to end
CloseHandle(hd);