首页 > 编程语言 > 详细

c线程传递多个参数,使用结构体

时间:2020-02-07 12:31:22      阅读:86      评论:0      收藏:0      [点我收藏+]
#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);
}

  

c线程传递多个参数,使用结构体

原文:https://www.cnblogs.com/luckygxf/p/12271700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!