4. API 比较细节 |
#include <pthread.h>
int pthread_condattr_init (pthread_condattr_t *attr)
int pthread_condattr_destroy (pthread_condattr_t *attr)
int pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared)
int pthread_condattr_getpshared (pthread_condattr_t *attr, int *pshared)
pthread_condattr_init() 将与这个对象相联系的属性初始化成它们缺省的值。在执行期间,由线索系统分配存储器。pthread_condattr_destroy()移走那个存储器,属性对象变得无效。
缺省的属性值为:
pthread_condattr_t cattr;
ret = pthread_condattr_init (&cattr); /* initialize an attribute to default value */ ret = pthread_condattr_destroy (&cattr); /* destroy an attribute */
属性pshared定义用此属性对象初始化的条件变量的同步范围。PTHREAD_SHARE_PRIVATE 导致行为如同在cond_init () 调用中的USYNC_THREAD 标识,那是一个局部条件变量。PTHREAD_SHARE_PROCESS 等价全局条件变量。
pthread_condattr_t cattr;
int pshared;
ret = pthread_condattr_getpshared (&cattr, &pshared); /* get pshared of cond */
ret = pthread_condattr_setpshared (&cattr, PTHREAD_SHARE_PROCESS); /* all processes */
ret = pthread_condattr_setpshared (&cattr, PTHREAD_SHARE_PRIVATE); /* within a process */
Copyright: NPACT |