当前位置:网站首页>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
边栏推荐
- [algorithm] sword finger offer2 golang interview question 5: maximum product of word length
- Code example of MATLAB reading GNSS observation value o file
- Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
- Role movement in the first person perspective
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- Answer to "software testing" exercise: Chapter 1
- [algorithm] sword finger offer2 golang interview question 2: binary addition
- Record: I accidentally wrote a recursion next time
- View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
- [rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
猜你喜欢
阿里云一面:并发场景下的底层细节 - 伪共享问题
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Experience summary of autumn recruitment of state-owned enterprises
Design a key value cache to save the results of the most recent Web server queries
Alibaba cloud microservices (IV) service mesh overview and instance istio
[algorithm] sword finger offer2 golang interview question 1: integer division
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
Wechat applet development experience
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Small exercise of library management system
随机推荐
[rtklib 2.4.3 B34] version update introduction I
162. Find peak - binary search
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
String class
RTKLIB: demo5 b34f. 1 vs b33
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
Record: Navicat premium can't connect to MySQL for the first time
A brief introduction to the database of tyut Taiyuan University of technology in previous years
Usage differences between isempty and isblank
TYUT太原理工大学2022数据库大题之数据库操作
XV Function definition and call
IText 7 generate PDF summary
Inheritance and polymorphism (I)
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
Heap sort [handwritten small root heap]
Introduction pointer notes
阿里云微服务(四) Service Mesh综述以及实例Istio
初识C语言(上)
染色法判定二分图
Wechat applet development experience