当前位置:网站首页>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
边栏推荐
- Role movement in the first person perspective
- [algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
- Database operation of tyut Taiyuan University of technology 2022 database
- 几道高频的JVM面试题
- Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
- Introduction and use of redis
- TYUT太原理工大学2022数据库大题之概念模型设计
- How to ensure data consistency between MySQL and redis?
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- String class
猜你喜欢

继承和多态(下)
![Heap sort [handwritten small root heap]](/img/f0/6efda3c6f499a32671a935dd2f21db.png)
Heap sort [handwritten small root heap]

Database operation of tyut Taiyuan University of technology 2022 database

如何保障 MySQL 和 Redis 的数据一致性?

Redis介绍与使用

2022 National Games RE1 baby_ tree
![Fundamentals of UD decomposition of KF UD decomposition [1]](/img/e9/564e0163c3756c0ba886913f1cfaef.jpg)
Fundamentals of UD decomposition of KF UD decomposition [1]

Inheritance and polymorphism (I)

Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]
随机推荐
Small exercise of library management system
Tyut outline of 2022 database examination of Taiyuan University of Technology
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
Answer to "software testing" exercise: Chapter 1
Rt-ppp test using rtknavi
Fundamentals of UD decomposition of KF UD decomposition [1]
抽象类和接口
Shortest Hamilton path (pressure DP)
TYUT太原理工大学往年数据库简述题
Introduction and use of redis
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Record: the solution of MySQL denial of access when CMD starts for the first time
Basic DOS commands
Database operation of tyut Taiyuan University of technology 2022 database
[算法] 剑指offer2 golang 面试题1:整数除法
How do architects draw system architecture blueprints?
TYUT太原理工大学2022数据库大题之数据库操作
记录:动态Web项目servlet访问数据库404错误之解决
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology