pthread_getspecific()和pthread_setspecific()的使用方法
来源:互联网 发布:美工岗位职责是那些 编辑:程序博客网 时间:2024/05/21 11:13
pthread_getpecific和pthread_setspecific实现同一个线程中不同函数间共享数据的一种很好的方式。
#include <stdio.h>#include <stdlib.h>#include <pthread.h>pthread_key_t key;void func1(){int *tmp = (int*)pthread_getspecific(key);printf("%d is fun is %s\r\n",*tmp,__func__);}void *tthread_fun(void* args){pthread_setspecific(key,args);int *tmp = (int*)pthread_getspecific(key);printf("%d is in zhu %s\r\n",*(int*)args,__func__);*tmp+=1;func1();return (void*)0;}void *thread_fun(void *args){pthread_setspecific(key,args);int *tmp = (int*)pthread_getspecific(key);//获得线程的私有空间printf("%d is runing in %s\n",*tmp,__func__);*tmp = (*tmp)*100;//修改私有变量的值func1();return (void*)0;}int main(){pthread_t pa, pb;pthread_key_create(&key,NULL);pthread_t pid[3];int a[3]={100,200,300};int i=0;for(i=0;i<3;i++){pthread_create(&pid[i],NULL,tthread_fun,&a[i]);pthread_join(pid[i],NULL);}return 0;}
- pthread_getspecific()和pthread_setspecific()的使用方法
- pthread_getspecific和pthread_setspecific使用
- pthread_getspecific和pthread_setspecific
- pthread_getspecific和pthread_setspecific使用
- pthread_getspecific和pthread_setspecific使用
- pthread_getspecific和pthread_setspecific使用
- pthread_setspecific,pthread_getspecific
- pthread_once、pthread_key_create和pthread_getspecific和pthread_setspecific
- 线程局部存储-pthread_getspecific和pthread_setspecific使用
- pthread_once,pthread_key_create,pthread_setspecific,pthread_getspecific
- pthread_setspecific函数与pthread_getspecific函数
- pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据
- pthread_getpecific和pthread_setspecific
- pthread_setspecific的一段代码
- TSD相关的 4 个函数: pthread_key_create(); pthread_key_delete(); pthread_getspecific(); pthread_sets
- freeradius-server-2.1.12 undefined reference to `pthread_getspecific' 的问题
- pthread库中操作线程专有数据的函数:pthread_key_create,pthread_setspecific,pthread_gtespecific,pthread_key_delete
- pthread_setspecific出现coredump
- c#Windows Mobile WiFi开启和关闭
- ios应用程序生命周期
- python lambda函数
- POJ 3667
- 真正的冒泡排序
- pthread_getspecific()和pthread_setspecific()的使用方法
- python switch函数
- 在github上部署第二个repository
- Unix编程艺术——Unix哲学
- 读一本跟技术无关的书籍
- 调用支付宝 报Undefined symbols for architecture armv7 _CreateRSADataVerifier的错误
- 笑话
- python 内建函数
- SSH 配置文件管理