线程本地存储:pthread_key_t
来源:互联网 发布:mac下载软件怎么删除 编辑:程序博客网 时间:2024/06/04 22:15
一、代码
pthread_key_t
pthread_key_create()、pthread_key_delete()
pthread_setspecific()、pthread_getspecific()
#include <stdlib.h>#include <stdio.h>#include <pthread.h>//step 1static pthread_key_t g_key;void* thread_proc(void* arg){ int id = pthread_self(); //step 3 pthread_setspecific(g_key, &id); //step 3 int key = *(int*)pthread_getspecific(g_key); printf("thread 0x%x id is 0x%x\n", pthread_self(), key); return NULL;}int main(int argc, char* argv[]){ pthread_t tid[10]; int i; //step 2 pthread_key_create(&g_key, NULL); for (i=0;i<10;i++) pthread_create(&tid[i], NULL, thread_proc, NULL); for (i=0;i<10;i++) pthread_join(tid[i], NULL); //step 2 pthread_key_delete(g_key); return 0;}二、运行结果
0 0
- 线程本地存储:pthread_key_t
- pthread_key_t 线程存储相关
- linux中的线程本地存储pthread_key_t和pthread_once
- 线程私有存储空间--pthread_key_t
- Linux线程私有数据pthread_key_t
- 线程本地存储 (TLS)
- 线程本地存储 (TLS)
- 线程本地存储 (TLS)
- 线程本地存储(TLS)
- DLL 线程本地存储
- 线程本地存储 (TLS)
- 线程本地存储
- DLL, 线程本地存储
- 线程本地存储
- C++线程本地存储
- 线程本地存储
- 20.5 线程本地存储
- 线程本地存储
- java中的值传递和引用传递
- 基础知识
- javascript 中的innerHTML的用法
- SNMP-简单网络管理协议简介
- 小谈ONLINE-GAME服务器端设计(1、2)
- 线程本地存储:pthread_key_t
- ZOJ 2316 Matrix Multiplication
- Redis + EJB 实现缓存(二)
- 颠倒的价牌——第四届蓝桥杯省赛C语言A组第4题
- [IT]C/S自动升级程序原理
- 小谈ONLINE-GAME服务器端设计(3)
- 小谈ONLINE-GAME服务器端设计(4)
- 使用CBitmapButton类创建位图按钮
- 辛星整理Linux中查看版本信息的若干方法