#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h> //#######################################################
//
// 李刚
// 2016.8.17
// pthread 线程参数传递
//
//######################################################## struct CTime{
int id;
char name[12];
char Num[12];
}; void *GetThread(void *arg){
struct CTime *t_time = (struct CTime *)arg;
// printf("pthread_t=%d\n",(int)pthread_self()); printf("%d\n" , t_time->id);
printf("%s\n" , t_time->name);
printf("%s\n" , t_time->Num); return 0;
} void *GetInstace(void * arg){
int* a = ((void **)arg)[0];
float* b = ((void **)arg)[1];
char* c = ((void **)arg)[2]; printf("this is thread: %d, %.3f, %s\n", *a, *b, c); return 0;
} int main(int argc, char*argv[]){
pthread_t tid;
int err = 0;
pthread_attr_t attr;
struct CTime t_time;
int a = 12;
float b = 23.5f;
char c[] = "hello,world"; void *arg[3] = {&a, &b, c}; // t_time.id =12;
memcpy(t_time.name, "tom json", sizeof("tom json"));
memcpy(t_time.Num, "1234567", sizeof("1234567")); pthread_attr_init(&attr); //
if((err = pthread_create(&tid, &attr, &GetThread, (void *) &t_time)) != 0)
printf("Error err = %d\n", err); pthread_join(tid, NULL); if((err = pthread_create(&tid, &attr, &GetInstace, (void *) arg)) != 0)
printf("Error \n"); pthread_join(tid, NULL); return 0;
}

  

Linux pthread的更多相关文章

  1. Linux Pthread 深入解析(转-度娘818)

    Linux Pthread 深入解析   Outline - 1.线程特点 - 2.pthread创建 - 3.pthread终止         - 4.mutex互斥量使用框架         - ...

  2. linux pthread之学习篇

    在应用程序编程中,为了不影响与用户交互的性能,通常需要创建新的线程来处理一些比较耗时的. 不影响用户体验的工作.而这又通常分为两种情况: (1)需要临时创建一个线程来做某件特定的事,等事情做完时线程即 ...

  3. linux,pthread(转)

    互斥量.条件变量与pthread_cond_wait()函数的使用,详解(二)   1.Linux“线程” 进程与线程之间是有区别的,不过linux内核只提供了轻量进程的支持,未实现线程模型.Linu ...

  4. linux pthread【转】

    转自:http://www.cnblogs.com/alanhu/articles/4748943.html Posix线程编程指南(1) 内容:  一. 线程创建  二.线程取消 关于作者  线程创 ...

  5. Linux pthread 线程池实现

    基于pthread封装了一个简易的ThreadPool,具有以下特性: 1.具有优先级的任务队列 2.线程池大小可以二次调整,增加线程或者删除空闲线程 3.任务两种重写方式,重写run或者使用函数回调 ...

  6. linux pthread多线程编程模板

    pthread_create() 创建线程,pthread_join()让线程一直运行下去. 链接时要加上-lpthread选项. pthread_create中, 第三个参数为线程函数,定义如下: ...

  7. Linux g++ 编译添加 pthread

    If you are going to compile a C program with pthread.h in LINUX using GCC or G++ you will have to us ...

  8. [转]Linux 的多线程编程的高效开发经验

    Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多线程 API 有一些细微和隐晦的差别.不注意这些 Linux 上的一些开发陷阱,常常会导致程序问题不穷,死锁不断.本文中我们 ...

  9. Linux 的多线程编程的高效开发经验(转)

    http://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/ 背景 Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多 ...

随机推荐

  1. <转>卷积神经网络是如何学习到平移不变的特征

    After some thought, I do not believe that pooling operations are responsible for the translation inv ...

  2. 分享 Ionic 开发 Hybrid App 中遇到的问题以及后期发布 iOS/Android 的方方面面

    此篇文章主要整理了最近在使用 Ionic 开发 Hybrid App 过程中遇到的一些疑难点以及后期发布生成 iOS 和 Android 版本过程中的种种问题. 文章目录 Ionic 简介和项目需求介 ...

  3. 【JavaScript】Html form 提交表单方式

    源:http://blog.csdn.net/wang02011/article/details/6299517 1.input[type='submit'] 2.input[type='image' ...

  4. 软件工程(FZU2015)赛季得分榜,第五回合

    目录 第一回合 第二回合 第三回合 第四回合 第五回合 第6回合 第7回合 第8回合 第9回合 第10回合 第11回合 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分 ...

  5. Function构造函数

    使用Function构造函数, 也能够创建函数, 和使用关键字function定义函数有几点区别: 使用function关键字这样定义函数: var f = function(x,y) {return ...

  6. Internet Download Manager 6.27.1 中文特别版(IDM)

    软件介绍: 软件名称:Internet Download Manager(IDM) 软件大小:5.09M软件语言:简体中文 软件官网:http://www.internetdownloadmanage ...

  7. 解决:ERROR: Cannot launch Jack server

    问题重现: Install: /home/dinphy/sm/out/target/product/ido/system/lib/libdl.so java -Xmx3500m -jar /home/ ...

  8. 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律

    F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...

  9. Codeforces Round #374 (Div. 2)

    A题和B题是一如既往的签到题. C题是一道拓扑序dp题,题意是给定一个DAG,问你从1号点走到n号点,在长度不超过T的情况下,要求经过的点数最多,换个思维,设dp[i][j]表示到i号点时经过j个点的 ...

  10. NOIP2016呵呵记

    经过了一年的想象和臆测,经历了学长们的几次考试,通过老师的言语莫名感受过了所谓oi式压力之后,自己的考试也终于到来了. 考前的生活也没有想象中的那么充实,无非跟着神犇刷刷题,讨论算法,学点新技巧,然后 ...