当前位置:网站首页>Atomic and nonatomic
Atomic and nonatomic
2022-07-06 13:15:00 【yokan_ de_ s】
Because the difference lies in thread safety, it can be regarded as a multi-threaded interview question
atomic Atomic operations , It is also called thread safety
nonatomic It's non atomic operation , The essence is that you must lock to be thread safe
if (!atomic) {
oldValue = *slot;
*slot = newValue;
} else {
spinlock_t& slotlock = PropertyLocks[slot];
slotlock.lock();
oldValue = *slot;
*slot = newValue;
slotlock.unlock();
}
In fact, there is no need to explain too much , Just look at the source code , This will determine whether it is atomic, If yes , Just add a lock , Only one thread can modify at a time
Not recommended for use atomic, Because even normal calls will be locked , This code efficiency is very low , Lock where you need it l
边栏推荐
- TYUT太原理工大学往年数据库简述题
- 国企秋招经验总结
- 闇の連鎖(LCA+树上差分)
- MySQL backup -- common errors in xtrabackup backup
- TYUT太原理工大学2022数据库之关系代数小题
- Implementation of Excel import and export functions
- [算法] 剑指offer2 golang 面试题1:整数除法
- View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
- Novatel board oem617d configuration step record
- A brief introduction to the database of tyut Taiyuan University of technology in previous years
猜你喜欢
How to ensure data consistency between MySQL and redis?
Iterable、Collection、List 的常见方法签名以及含义
[算法] 剑指offer2 golang 面试题2:二进制加法
The earth revolves around the sun
System design learning (III) design Amazon's sales rank by category feature
[GNSS data processing] Helmert variance component estimation analysis and code implementation
Tyut Taiyuan University of technology 2022 introduction to software engineering summary
一文搞定 UDP 和 TCP 高频面试题!
[算法] 劍指offer2 golang 面試題2:二進制加法
Fundamentals of UD decomposition of KF UD decomposition [1]
随机推荐
继承和多态(下)
[rtklib 2.4.3 B34] version update introduction I
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
阿里云微服务(三)Sentinel开源流控熔断降级组件
TYUT太原理工大学2022数据库大题之数据库操作
TYUT太原理工大学2022“mao gai”必背
TYUT太原理工大学2022软工导论考试题型大纲
[algorithm] sword finger offer2 golang interview question 1: integer division
分支语句和循环语句
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
架构师怎样绘制系统架构蓝图?
IText 7 generate PDF summary
Inheritance and polymorphism (I)
Redis介绍与使用
TYUT太原理工大学2022软工导论简答题
Dark chain lock (lca+ difference on tree)
GNSS positioning accuracy index calculation
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
Wechat applet development experience