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\n", couple1->age, couple1->husband, couple1->wife);
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM