zoukankan      html  css  js  c++  java
  • c线程传递多个参数,使用结构体

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <pthread.h>
    #include <unistd.h>
    
    #include "header-demo.h"
    
    void display(void *couple);
    
    typedef struct Persons {
        int age;
        char *husband;
        char *wife;
    } Couple;
    
    int main() {
        pthread_t pthread;
        Couple *couple = (Couple *)alloca(sizeof(Couple));
        couple->age = 10;
        couple->wife = "zhu";
        couple->husband = "guan";
    //    strcpy(couple->husband, "guan");
    //    strcpy(couple->wife, "zhu");
        pthread_create(&pthread, NULL, display, (void *)couple);
        pthread_join(&pthread, NULL);
    
        return 0;
    }
    
    void display(void *couple) {
        Couple *couple1 = (Couple *)couple;
        printf("age:%d, name1: %s, name2:%s
    ", couple1->age, couple1->husband, couple1->wife);
    }
    

      

  • 相关阅读:
    字典树
    Floyd算法
    迪杰斯特拉算法---单源点最短路径
    二叉树的遍历
    图的遍历
    二叉排序树
    拓扑排序
    开发中框架的发展
    IOC
    JS操作JSON总结
  • 原文地址:https://www.cnblogs.com/luckygxf/p/12271700.html
Copyright © 2011-2022 走看看