zthread学习 实例六 访问控制
来源:互联网 发布:windows.old删除之后 编辑:程序博客网 时间:2024/05/13 03:38
就是对共享资源的同步访问,以免造成不确定的状态。
Zhread库是基于Mutex临界区来组建同步机制的。
Guard<>模板很方便的定义了同步机制,它在创建时用acquire()来获得一个Lockable对象,被销毁时用release()来释放这个锁。Guard对象的创建很好的利用了变量作用域概念。例如:
void fun()
{
... ...
{ //特意添加的用于控制Guard作用域的括号
Guard<Mutex> g(Lock);
... ...//重点临界区代码
}
}
Zhread库中给Guard<>提供了4种类型的锁策略:
1、CompoundScope
Note: Locking policy that aggregates two policies that share a target.It is not appropriate to use with any type of OverlappedScope
2、LockedScope(默认)
Note: Locking policy for Lockable objects. This policy acquire()s a Lockable when the protection scope is created, and it release()s a Lockable when the scope is destroyed.
3、UnlockedScope(解锁)
Note: Locking policy for Lockable objects. This policy release()s a Lockable when the protection scope is created, and it acquire()s a Lockable when the scope is destroyed.
4、TimedLockedScope(带时间)
Note: Locking policy that attempts to enterScope some resource in a certain amount of time using an tryEnterScope-relase protocol.
5、OverlappedScope
Note: Locking policy allows the effective scope of two locks to overlap by releasing and disabling one lock before its Guard does so.
- zthread学习 实例六 访问控制
- zthread学习 实例六 访问控制
- zthread学习 实例一
- zthread学习 实例二
- zthread学习 实例四 让步、休眠、优先级
- zthread学习 实例七 线程本地存储
- zthread学习 实例十一 信号量机制
- zthread学习 实例四 让步、休眠、优先级
- zthread学习 实例七 线程本地存储
- zthread学习 实例十四 信号量机制
- zthread学习 实例十二 ZThread库基本结构的规纳
- zthread学习 实例十五ZThread库基本结构的规纳
- zthread学习 实例三 使用Executor器来执行线程
- zthread学习 实例五 非任务对象的生存期
- zthread学习 实例十 线程间的协助(一)
- zthread学习 实例十 线程间的协助(二)
- zthread学习 实例五 非任务对象的生存期
- zthread学习 实例十 线程间的协助(一)
- 笔记本电脑无法无线上网 提示“区域中找不到无线网络”
- USPLASH替换UBUNTU启动进度条界面 (适用于 9.04以前的版本)
- 简历引发的郁闷
- 正整数中数字1的计数问题 - 采用分治法快速计算f(n)(下)
- 二分搜索算法(折半查找)原理以及递归(recuition),迭代(iteration)的两种实现源代码
- zthread学习 实例六 访问控制
- Java集合类详解
- 搜搜健康中心项目推广
- java集合类
- ubuntu 配置jdk环境变量
- javascript中visibility和display的区别
- CLR与MFC混合编程
- C/C++查找一定范围内的素数(筛法)
- 英文版VS2010制作中文环境安装包