#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. 51Nod-1265 四点共面

    51Nod 1265 : http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1265 1265 四点共面 基准时间限制:1 秒 ...

  2. MongoDB学习笔记一

    操作系统:Windows7 1.下载MongoDB 2.6.5服务端,并安装 网址:http://pan.baidu.com/s/1dDfoJAh 说明:网上很多都不需要安装的,这个需要安装. 2.添 ...

  3. Javascript读写文件

    <script type="text/javascript" language="javascript"> //读文件 function readF ...

  4. epub电子书--目录结构介绍

    epub电子书简介 epub全称为Electronic Publication的缩写,意为:电子出版, epub于2007年9月成为国际数位出版论坛(IDPF)的正式标准,以取代旧的开放Open eB ...

  5. jquery里互为逆过程的方法

    jquery里互为逆过程的方法reverse 在jquery里,有不少互为逆过程的方法,如parent()与children(),parents()与find(),first()和last()等,这些 ...

  6. 【kAriOJ】离散数学 构造群码 极大似然法解码

    A. 编程题1 构造群码 时间限制 1000 ms 内存限制 65536 KB 题目描述 针对给定H,计算群码编码函数eH,并计算给定字的码字. 输入格式 第一行输入两个整数m,n:(m < n ...

  7. java之线程

    java之线程 一:线程: 线程是什么呢?线程,有时被称为轻量级进程是程序执行流的最小单元.一个标准的线程由线程ID,当前指令指针(PC),寄存器集合和堆栈组成.另外,线程是进程中的一个实体,是被系统 ...

  8. 关于获取、设置css样式封装的函数入门版

    <html> <head> <meta charset="UTF-8"> <title>CSS样式的获取和设置:简单版</ti ...

  9. BZOJ 2120: 数颜色

    2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MBSubmit: 3623  Solved: 1396[Submit][Status][Discuss] ...

  10. 【BZOJ-3747】Kinoman 线段树

    3747: [POI2015]Kinoman Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 715  Solved: 294[Submit][Stat ...