我写了以下简单的代码:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* printThreadFunction()
{
puts("***got here*****");
}
int main (int argc, char *argv[])
{
pthread_t printThread;
if (pthread_create(&printThread, NULL, printThreadFunction, NULL) != 0) {
perror("pthread_create");
exit(1);
}
pthread_join(printThread, NULL);
}
此代码按照我的预期打印***got here*****
。但是,如果我将printThreadFunction()
更改为:
void* printThreadFunction()
{
puts("***got here*****");
while(1); // change here
}
所以代码进入无限循环,但没有对屏幕进行打印 - 为什么会这样?