4. API 比较细节 |
#include <thread.h>
int thr_keycreate (thread_key_t *keyp, void (*destructor) (void *))
int thr_setspecific (thread_key_t key, void *value)
int thr_getspecific (thread_key_t key, void **value)
#include <pthread.h>
int pthread_key_create (pthread_key_t *keyp, void (*destructor) (void *))
int pthread_setspecific (pthread_key_t key, void *value) void * pthread_getspecific (pthread_key_t key)
int pthread_key_delete (pthread_key_t key)
在Solaris 中
thread_key_t mykey;
int ret;
ret = thr_keycreate (&mykey, NULL); /* key create without destructor */
ret = thr_keycreate (&mykey, dest_func); /* key create with destructor */
在pthreads 中
pthread_key_t mykey;
int ret;
ret = pthread_key_create (&mykey, NULL); /* key create without destructor */
ret = pthread_key_create (&mykey, dest_func); /* key create with destructor */
在Solaris 中
thread_key_t mykey;
void *val;
int ret;
ret = thr_getspecific (mykey, &val); /* mykey is previously created key */
在pthreads 中
pthread_key_t mykey;
void *val;
val = pthread_getspecific (mykey); /* mykey is previously created key */
在Solaris 中
thread_key_t mykey;
void *val;
int ret;
ret = thr_setspecific (mykey, val); /* mykey is previously created key */
在pthreads 中
pthread_key_t mykey;
void *val;
int ret;
ret = pthread_setspecific (mykey, val); /* mykey is previously created key */
pthreads 提供一种方法,以释放一个已存在的线索说明数据关键字。当试图访问一些不再有效的线索说明数据集时,使用它会引起错误返回。在Solaris 中没有可比较的函数。
一旦删除了一个关键字,通过pthread_setspecific() 或者pthread_getspecific() 对它的引用,导致EINVAL错。程序员负责在调用删除函数前释放任何线索说明资源。此函数不嵌入任何解构器。
pthread_key_t mykey;
int ret;
ret = pthread_key_delete (mykey); /* mykey is previously created key */
Copyright: NPACT |