Linux pthread
#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的更多相关文章
- Linux Pthread 深入解析(转-度娘818)
Linux Pthread 深入解析 Outline - 1.线程特点 - 2.pthread创建 - 3.pthread终止 - 4.mutex互斥量使用框架 - ...
- linux pthread之学习篇
在应用程序编程中,为了不影响与用户交互的性能,通常需要创建新的线程来处理一些比较耗时的. 不影响用户体验的工作.而这又通常分为两种情况: (1)需要临时创建一个线程来做某件特定的事,等事情做完时线程即 ...
- linux,pthread(转)
互斥量.条件变量与pthread_cond_wait()函数的使用,详解(二) 1.Linux“线程” 进程与线程之间是有区别的,不过linux内核只提供了轻量进程的支持,未实现线程模型.Linu ...
- linux pthread【转】
转自:http://www.cnblogs.com/alanhu/articles/4748943.html Posix线程编程指南(1) 内容: 一. 线程创建 二.线程取消 关于作者 线程创 ...
- Linux pthread 线程池实现
基于pthread封装了一个简易的ThreadPool,具有以下特性: 1.具有优先级的任务队列 2.线程池大小可以二次调整,增加线程或者删除空闲线程 3.任务两种重写方式,重写run或者使用函数回调 ...
- linux pthread多线程编程模板
pthread_create() 创建线程,pthread_join()让线程一直运行下去. 链接时要加上-lpthread选项. pthread_create中, 第三个参数为线程函数,定义如下: ...
- 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 ...
- [转]Linux 的多线程编程的高效开发经验
Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多线程 API 有一些细微和隐晦的差别.不注意这些 Linux 上的一些开发陷阱,常常会导致程序问题不穷,死锁不断.本文中我们 ...
- Linux 的多线程编程的高效开发经验(转)
http://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/ 背景 Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多 ...
随机推荐
- title与alt的区别
html中的title属性和alt属性让人有些混淆. 以前不知道有title这个属性,第一次用到它时,就和alt产生了混淆.一位朋友告诉我说,alt是图片img标签里用的,title是超链接里用的, ...
- 编写、部署、应用JavaBean
编写javabean 编写javabean实质上就是编写一个java类.设计javabean类就是要设计这个javabean的属性和方法,类的方法的命名遵循以下规则: 1)如果成员变量的名字是xx ...
- caffe的python接口学习(8):caffemodel中的参数及特征的抽取
如果用公式 y=f(wx+b) 来表示整个运算过程的话,那么w和b就是我们需要训练的东西,w称为权值,在cnn中也可以叫做卷积核(filter),b是偏置项.f是激活函数,有sigmoid.relu ...
- SignalR 实现Web多人聊天室
ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信.什么是实时通信的Web呢?就是让客户端(Web页面)和服务器端可以互相通知消 ...
- mysql Workbench 执行删除命令
SET SQL_SAFE_UPDATES = 0;delete from table1; SET SQL_SAFE_UPDATES = 1;
- Advanced Office Password Recovery如何设置快捷方式
一般软件安装成功之后都会在桌面上形成快捷方式以方便使用,但是一些用户发现Advanced Office Password Recovery这种office密码破解工具安装成功后桌面上没有出现快捷方式, ...
- 数据结构图文解析之:直接插入排序及其优化(二分插入排序)解析及C++实现
0. 数据结构图文解析系列 数据结构系列文章 数据结构图文解析之:数组.单链表.双链表介绍及C++模板实现 数据结构图文解析之:栈的简介及C++模板实现 数据结构图文解析之:队列详解与C++模板实现 ...
- BZOJ 2882: 工艺
2882: 工艺 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 599 Solved: 268[Submit][Status][Discuss] D ...
- end2end learning 端到端学习
在DeepLearning的文章中有看到end2end一次,作者们似乎都比较喜欢这个end2end learning的方式.那么到底啥是end2end? 找了一下相关论文,没找到专门讲这个概念的,看来 ...
- NOIp2016 十连测 round1
Claris大爷出的一套模拟题.问别人要到了一份题,加深了自己NOIp要滚粗的感觉. Matser zzDP题,我只能说我第一遍写的时候还写崩了QAQ. //master //by Cydiater ...