IOS NSConditionLock 条件锁 NSCondition 断言
来源:互联网 发布:绿地集团知乎 编辑:程序博客网 时间:2024/05/22 08:14
NSConditionLock 条件锁 NSCondition 断言
NSConditionLock 继承类NSObject 遵从的协议NSLocking NSObject
NSConditionLock 类定义特定的、用户定义的条件锁
协议NSLocking 方法 lock unlock
//初始化一个NSConditionLock对象
- (id)initWithCondition:(NSInteger)condition
//返回一个Condition
- (NSInteger)condition
//获取和释放锁
1、– (BOOL)lockBeforeDate:(NSDate *)limit
//在指定时间前尝试获取锁,若成功则返回YES 否则返回NO
2、– (void)lockWhenCondition:(NSInteger)condition
//同上,只是又加上了一个时间
4、– (BOOL)tryLock //尝试着获取锁
5、– (BOOL)tryLockWhenCondition:(NSInteger)condition
//如果接收对象的condition与给定的condition相等,则尝试获取锁
6、– (void)unlockWithCondition:(NSInteger)condition
//解锁并设置接收对象的condition
//访问方法
– setName:
– name
NSCondition 类 断言
用一个NSCondition类对象的步骤
1、Lock the condition object.
2、Test a boolean predicate. (This predicate is a boolean flag or other variable in your code that indicates whether it is safe to perform the task protected by the condition.)
3、If the boolean predicate is false, call the condition object’s wait or waitUntilDate: method to block the thread. Upon returning from these methods, go to step 2 to retest your boolean predicate. (Continue waiting and retesting the predicate until it is true.)
4、If the boolean predicate is true, perform the task.
5、Optionally update any predicates (or signal any conditions) affected by your task.
6、When your task is done, unlock the condition object.
英语不太好也就不翻译了,大概意思都能看懂
下面看一下方法
//使线程等待
1、- (void)wait //阻塞当前线程,直到收到信号
2、- (BOOL)waitUntilDate:(NSDate *)limit
//阻塞当前线程,直到收到信号或到达指定的时间
///发信号给阻塞的线程
1、- (void)signal //唤醒一个阻塞的线程
2、- (void)broadcast //唤醒所有阻塞的线程
///访问方法
– setName:
NSConditionLock 继承类NSObject 遵从的协议NSLocking NSObject
NSConditionLock 类定义特定的、用户定义的条件锁
协议NSLocking 方法 lock unlock
//初始化一个NSConditionLock对象
- (id)initWithCondition:(NSInteger)condition
//返回一个Condition
- (NSInteger)condition
//获取和释放锁
1、– (BOOL)lockBeforeDate:(NSDate *)limit
//在指定时间前尝试获取锁,若成功则返回YES 否则返回NO
2、– (void)lockWhenCondition:(NSInteger)condition
//尝试获取锁。在加锁成功前接收对象的Condition必须与参数Condition 相同
3、– (BOOL)lockWhenCondition:(NSInteger)condition beforeDate:(NSDate *)limit//同上,只是又加上了一个时间
4、– (BOOL)tryLock //尝试着获取锁
5、– (BOOL)tryLockWhenCondition:(NSInteger)condition
//如果接收对象的condition与给定的condition相等,则尝试获取锁
6、– (void)unlockWithCondition:(NSInteger)condition
//解锁并设置接收对象的condition
//访问方法
– setName:
– name
NSCondition 类 断言
用一个NSCondition类对象的步骤
1、Lock the condition object.
2、Test a boolean predicate. (This predicate is a boolean flag or other variable in your code that indicates whether it is safe to perform the task protected by the condition.)
3、If the boolean predicate is false, call the condition object’s wait or waitUntilDate: method to block the thread. Upon returning from these methods, go to step 2 to retest your boolean predicate. (Continue waiting and retesting the predicate until it is true.)
4、If the boolean predicate is true, perform the task.
5、Optionally update any predicates (or signal any conditions) affected by your task.
6、When your task is done, unlock the condition object.
英语不太好也就不翻译了,大概意思都能看懂
下面看一下方法
//使线程等待
1、- (void)wait //阻塞当前线程,直到收到信号
2、- (BOOL)waitUntilDate:(NSDate *)limit
//阻塞当前线程,直到收到信号或到达指定的时间
///发信号给阻塞的线程
1、- (void)signal //唤醒一个阻塞的线程
2、- (void)broadcast //唤醒所有阻塞的线程
///访问方法
– setName:
– name
0 0
- IOS NSConditionLock 条件锁 NSCondition 断言
- IOS NSConditionLock 条件锁 NSCondition 断言
- iOS-NSConditionLock:条件锁
- ios中的锁(Lock) NSLock,NSConditionLock,NSRecursiveLock,NSCondition
- IOS NSLocking协议,NSLock,NSConditionLock,NSRecursiveLock,NSCondition
- NSCondition和NSConditionLock
- iOS NSCondition
- iOS NSCondition
- ios NSConditionLock 解释
- ios NSConditionLock 解释
- 线程锁-NSConditionLock
- iOS NSCondition讲解
- ios线程阻塞之NSCondition
- 【NSCondition】
- NSCondition
- NSCondition
- Objective c中的锁 NSLock,NSConditionLock,NSRecursiveLock
- 断言 IOS
- Linux下软AP功能之Hostapd介绍
- 利用HOARE_PARTITION重写QUICKSORT
- 【BZOJ】【P1260】【CQOI2007】【涂色paint】【题解】【dp】
- Android 实现登录界面和功能实例
- 注释引起的错误
- IOS NSConditionLock 条件锁 NSCondition 断言
- Hdu 3625 Examining the Rooms[第一类斯特林数]
- ubuntu下链接动态库失败
- VS2005快捷键大全
- 孙鑫C++视频教程
- asp.net
- Transactional Topology简介
- Big Number(HDU 1018)
- sqlite3 插入数据的时候,返回SQLITE_CONSTRAINT