继续回到解决程序
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *sayhello(void *arg)
{
printf("hello, world! I'm son\n");
}
int main(void)
{
int error;
pthread_t son;
error = pthread_create(&son, NULL, sayhello, NULL);
printf("hello, world! I'm father\n");
return 0;
}
的问题上!
也即让“printf("hello, world! I'm son\n");”和“printf("hello, world! I'm father\n");”都能够执行。
《pthread_create()初体验》已经给出了三个解决办法:
方法1:在“return 0;”之前加上一句“sleep(1);”
方法2:在“父进程”所对应程序中加上一句“pthread_join()”
方法3:在“父进程”所对应程序中加上一句“pthread_exit(NULL)”
pthread_exit(NULL)和pthread_join()的功能差不多,只是后者从退出的子线程获取退出状态码(具体如何获取就不知道了)!
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *sayhello(void *args)
{
printf