线程安全的计数
作者:
Bearger | 来源:发表于
2017-05-26 14:37 被阅读70次
#import <libkern/OSAtomic.h>
/// a thread safe incrementing counter.
@interface _YYTextSentinel : NSObject
/// Returns the current value of the counter.
@property (atomic, readonly) int32_t value;
/// Increase the value atomically. @return The new value.
- (int32_t)increase;
@end
@implementation _YYTextSentinel {
int32_t _value;
}
- (int32_t)value {
return _value;
}
- (int32_t)increase {
return OSAtomicIncrement32(&_value);
}
@end
本文标题:线程安全的计数
本文链接:https://www.haomeiwen.com/subject/bncxfxtx.html
网友评论