#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. Linux Linux程序练习十九

    题目:编写一个同步服务器模型 要求: )客户端A主机给服务器B主机发送报文, )B服务器主机收到报文以后同时分发给C1主机.C2主机: )C1主机和C2主机打印出客户端A的报文 bug总结:本来这道题 ...

  2. c#读写txt

    附加到txt:StreamWriter sw =System.IO.File.AppendText(path); //绝对路径 sw.Write("写入内容"); 写入到txt: ...

  3. IIS7注册本机模块

    问题描述:打开mp4文件要映射给mod_h264_streaming.dll(http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Intern ...

  4. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  5. Redis从入门到精通之一:序篇

    Redis一直是我想好好研究的组件,但是之前受限于工作场景,没有真正意义的使用过.但是目前工作中,Redis作为主要的缓存组件来缓冲服务器的压力.所以,本序列主要结合实际工作中遇到的各种Redis的设 ...

  6. greenDao:操作数据库的开源框架

    greenDAO: Android ORM for your SQLite database 1. greenDao库获取 英文标题借鉴的是greendrobot官网介绍greenDao时给出的Tit ...

  7. CSS基本知识4-CSS行模型

    display:inline.block.inline-block block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度 i ...

  8. 第二次团队作业——预则立&&他山之石

    Deadline: 2016.10.16 22:00pm 一.确立团队选题,建立和初步熟悉团队git的协作方式.项目后续的代码.文档都要通过github增量式管理.实现文档的版本化和增量式管理. 二. ...

  9. RecyclerView

    学习到了 RecyclerView, 本来是ListView,但是我看的视频没有讲.主要是说取代ListView, 原因是更灵活更节省资源. 就是循环展现数据用的. 1. 引入 RecyclerVie ...

  10. Mysql连表之多对多

    说明 这里的文章是接着前面 Mysql连表一对多 写的. 连表多对多 可以理解成一夫多妻和一妻多夫. 男人表: nid name 1 xxx 2 yyy 3 zzz 女人表: nid name 1 a ...