当前位置:网站首页>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
边栏推荐
- Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
- 分支语句和循环语句
- 《软件测试》习题答案:第一章
- Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
- Realization of the code for calculating the mean square error of GPS Height Fitting
- [rtklib 2.4.3 B34] version update introduction I
- Usage differences between isempty and isblank
- Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
- Pride-pppar source code analysis
- Error: symbol not found
猜你喜欢

阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍

Redis介绍与使用

面渣逆袭:Redis连环五十二问,三万字+八十图详解。

系统设计学习(一)Design Pastebin.com (or Bit.ly)

Detailed explanation of balanced binary tree is easy to understand
![[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire](/img/c2/6f6c3bd4d70252ba73addad6a3a9c1.png)
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire

System design learning (III) design Amazon's sales rank by category feature

Alibaba cloud microservices (II) distributed service configuration center and Nacos usage scenarios and implementation introduction

阿里云一面:并发场景下的底层细节 - 伪共享问题

阿里云微服务(四) Service Mesh综述以及实例Istio
随机推荐
Inheritance and polymorphism (I)
阿里云一面:并发场景下的底层细节 - 伪共享问题
[算法] 剑指offer2 golang 面试题7:数组中和为0的3个数字
Fundamentals of UD decomposition of KF UD decomposition [1]
The port is occupied because the service is not shut down normally
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
Record: newinstance() obsolete replacement method
2-year experience summary, tell you how to do a good job in project management
TYUT太原理工大学2022数据库考试题型大纲
堆排序【手写小根堆】
How to ensure data consistency between MySQL and redis?
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
系统设计学习(三)Design Amazon‘s sales rank by category feature
Fairygui bar subfamily (scroll bar, slider, progress bar)
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
String类
Record: the solution of MySQL denial of access when CMD starts for the first time
TYUT太原理工大学2022数据库之关系代数小题
Problems and solutions of robust estimation in rtklib single point location spp
阿里云微服务(三)Sentinel开源流控熔断降级组件