#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. 解决ppt中视频不能播放的问题

    小伙伴一直在纠结一个问题,有个ppt,在其他人的电脑上可以正常播放其中的视频,但是在某一个电脑上却总是不能播放,一直没找到原因,俺们今早捯饬了一下,貌似找到一丢丢原因和解决办法了. #1,疑似原因 为 ...

  2. 20145233 2016-2017 1 linux题目总结

    20145233 2016-2017 1 linux题目总结 第一周考试知识汇总 判断:实验楼环境中所有的默认系统用户名和密码均为 shiyanlou.(x ). 填空:Linux Bash中,Ctr ...

  3. memcached

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...

  4. js打开新页面与关闭当前页面

    打开新的窗口window.open("help.html"); window.open("help.html"); 关闭页面<a href="j ...

  5. git-添加公钥

    安装完git后,打开开git bush 输入以下命令 git config --global user.name "Your Name" git config --global u ...

  6. iOS 适配https(AFNetworking3.0为例)

    众所周知,苹果有言,从2017年开始,将屏蔽http的资源,强推https楼主正好近日将http转为https,给还没动手的朋友分享一二 1.准备证书 首先找后台要一个证书(SSL证书,一般你跟后台说 ...

  7. CUDA程序设计(一)

    为什么需要GPU 几年前我启动并主导了一个项目,当时还在谷歌,这个项目叫谷歌大脑.该项目利用谷歌的计算基础设施来构建神经网络. 规模大概比之前的神经网络扩大了一百倍,我们的方法是用约一千台电脑.这确实 ...

  8. CommonJS,AMD,CMD区别

    学得比较晕,再次看commonjs,amd, cmd时好像还是没完全弄清楚,今天再整理一下: commonjs是用在服务器端的,同步的,如nodejs amd, cmd是用在浏览器端的,异步的,如re ...

  9. JavaScript 中对内存的一些了解

    在使用JavaScript进行开发的过程中,了解JavaScript内存机制有助于开发人员能够清晰的认识到自己写的代码在执行的过程中发生过什么,也能够提高项目的代码质量.其实关于内存的文章也有很多,写 ...

  10. BZOJ2815: [ZJOI2012]灾难

    传送门 学LCA的时候根本没意识到LCA可以有这么多玩法. 这玩意据说是个高级数据结构(支配树)的弱化版,蒟蒻没学过呀.所以出题人提出一个概念叫灾难树. 我理解的灾难树的意思实际上是属于DAG的一个子 ...