23,120
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *threadfuc(void *pvoid)
{
int id = (int)pvoid;
printf("Child thread %d says:Hello world!\n", id);
return NULL;
}
int main()
{
pthread_t tid1,tid2;
pthread_create(&tid1, NULL, &threadfuc, (void *)1);
pthread_create(&tid2, NULL, &threadfuc, (void *)2);
pthread_detach(tid1);
/* 第二个参数:等待线程的返回值 */
pthread_join(tid2, NULL);
printf("Main thread say:Hello world!\n");
return 0;
}