曲径通幽论坛

标题: pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据 [打印本页]

作者: beyes    时间: 2010-6-15 11:58
标题: pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据
原型
#include <pthread.h>

void *pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);

说明
TSD 的读写都通过上面两个专门的 Posix Thread 函数进行。

函数 pthread_setspecific() 将 pointer 的值 (不是锁指的内容) 与key 相关联。
函数 pthread_getspecific() 将与 key 相关联的数据读出来。返回的数据类型都是 void *,因此可以指向任何类型的数据。

代码示例:
http://www.groad.net/bbs/read.php?tid-2179.html




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2