设为首页 加入收藏

TOP

APUE学习之多线程编程(三):线程属性、同步属性(二)
2017-10-12 18:13:46 】 浏览:8759
Tags:APUE 习之 线程 编程 属性 同步
d_muteattr_t *attr, int pshared)

     类型属性控制住互斥量的锁定特性,值得注意的是其中的PTHREAD_MUTEX_RECURSIVE类型,此类型允许同一线程在互斥量解锁之前对该互斥量进行多次加锁。递归互斥量维护锁的基数,在解锁次数和加锁次数不相同的情况下,不解锁。

#include <pthread.h>
int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr, int *restrict type)
int pthread_mutexattr_settype(pthread_mutexattr *attr, int type)

     三、读写锁属性

     使用pthread_rwlockattr_init初始化pthread_rwlockattr_t结构,用pthread_rwlockattr_destroy销毁。
#include <pthread.h>
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)

     读写锁唯一属性是进程共享属性,与互斥量的进程共享属性相同。

#include <pthread.h>
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict attr, int *restrict pshared)
int pthread_rwlockattr_setpshared(const pthread_rwlockattr_t *attr, int * pshared)

     四、条件变量属性

     有一对用于初始化和销毁的函数。
#include <pthread.h>
int pthread_condattr_init(pthread_condattr_t *attr)
int pthread_condattr_destroy(pthread_condattr_t *attr)

     条件变量支持进程共享属性和时钟属性,其中进程共享属性与互斥量的进程共享属性相同。

#include <pthread.h>
int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr, int *restrict pshared)
int pthread_condattr_setpshared(const pthread_condattr_t *attr, int pshared)

     时钟属性控制pthread_cond_timedwait函数的超时参数tsptr采用的是哪个时钟。

#include <pthread.h>
int pthread_condattr_getclock(const pthread_condattr_t *restrict attr, clockid_t *restrict clock_id)
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux目录结构 下一篇linux基本知识0

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目