1 #include "head.h"
  2 
  3 struct node
  4 {
  5     int data;
  6     char ch;
  7 };
  8 
  9 void *func(void *arg)
 10 {
 11     struct node *mynode2;
 12 
 13     mynode2 = (struct node *)(arg);
 14     mynode2->data = 1;
 15     mynode2->ch = 'c';
 16 
 17     return mynode2;
 18 }
 19 
 20 int main()
 21 {
 22     struct node *mynode,*mynode1;
 23     int error;
 24     pthread_t tid;
 25 
 26     mynode = (struct node*)malloc(sizeof(struct node));
 27     if (error = pthread_create(&tid, NULL, func, mynode))
 28     {
 29         fprintf(stderr, "Failed to create thread:%s\n",strerror(error));
 30         return 0;
 31     }
 32     if (error = pthread_join(tid, (void **)&mynode1))
 33     {
 34         fprintf(stderr, "Failed to create thread:%s\n",strerror(error));
 35         return 0;
 36     }
 37     printf("mynode2:%d,%c\n",mynode1->data,mynode1->ch);
 38     }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案