linux下的最简单的线程应用代码

来源:互联网 发布:java合并list 编辑:程序博客网 时间:2024/05/17 09:14
#include<stdio.h>
#include <pthread.h>
#include<stdlib.h>
struct Demo
{
int a;
char b;
}demo = {1, 'q'};
void *mythread()
{
printf("this is thread\n");
     return ((void *)&demo);
}
int main()
{
 pthread_t id1;                                                                                                //创建线程的标示量
 int ret = pthread_create(&id1, NULL, (void*)mythread, NULL);                 // 创建线程
 struct Demo *d;

 pthread_join(id1, (void *)&d);                                                                       //运行线程 

 printf("%d, %c", d->a, d->b);

      pthread_exit(0);
 return 0;
}