我写了以下代码:
#include <pthread.h>
#include <stdio.h>
void* sayHello (void *x){
printf ("Hello, this is %d\n", (int)pthread_self());
return NULL;
}
int main (){
pthread_t thread;
pthread_create (&thread, NULL, &sayHello, NULL);
printf("HERE\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译和运行后,我看到了3种不同类型的输出.
当然我对第二个选项没关系,但是我不明白为什么如果我只创建一个线程,'sayHello'massege可以打印0或2次?