所以我有这个代码基本上创建一个线程并等待它结束。这个线程只打印Hello,“flush”只是在这里清理缓冲区。我在Windows 8.1上使用Eclipse(是的,这很糟糕,我知道)
void *first(void *id)
{
printf("Hello!\n");
fflush(stdout);
return NULL;
}
int main(void){
pthread_t threads;
printf("test\n");
fflush(stdout);
pthread_create(&threads, NULL, first, NULL);
pthread_join(threads, NULL);
printf("test2\n");
fflush(stdout);
//pthread_exit(NULL);
return 0;
}
在这个配置中,当Eclipse中的这个代码在运行模式下运行时,控制台会保持空白。 如果我在Debbug模式下启动它,我会在控制台中启用它:
test
Hello!
test2
如果我引用:
//pthread_create(&threads, NULL, first, NULL);
//pthread_join(threads, NULL);
我在运行模式下启动它,我在控制台中启用它:
test
test2
所以问题是,有人知道为什么当我使用pthread_create时,在运行模式下控制台中什么都没有,但Debbug模式中有什么东西?当我在运行模式下使用pthread_create时,如何在控制台中有一些东西?