atomic vs. nonatomic
Declaring a property atomic makes compiler generate additional code that prevents concurrent access to the property. This additional code locks a semaphore, then gets or sets the property, and then unlock the semaphore. Compared to setting or getting a primitive value or a pointer, locking and unlocking a semaphore is expensive (although it is usually negligible if you consider the overall flow of your app). And also the atomic property doesn't mean thread safety. The property read by one thread for mutiple times may be different when it's modifing by another thread. The thread safety is garanteed by a more complicate mechanism.
Since most of your classes under iOS, especially the ones related to UI, will be used in a single-threaded environment, it is safe to drop atomic (i.e. write nonatomic, because properties are atomic by default): even though the operation is relatively inexpensive, you do not want to pay for things that you do not need.
参考:
http://stackoverflow.com/questions/588866/whats-the-difference-between-the-atomic-and-nonatomic-attributes
http://stackoverflow.com/questions/17571338/why-properties-are-always-said-to-be-made-nonatomic-in-objective-c
atomic vs. nonatomic的更多相关文章
- 【iOS atomic、nonatomic、assign、copy、retain、weak、strong】的定义和区别详解
一.atomic与nonatomic 1.相同点 都是为对象添加get和set方法 2.不同点 atomic为get方法加了一把安全锁(及原子锁),使得方法get线程安全,执行效率慢 nonatomi ...
- IOS atomic与nonatomic,assign,copy与retain的定义和区别
IOS atomic与nonatomic,assign,copy与retain的定义和区别 atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作. ...
- Objective-C:三种文件导入的方式以及atomic和nonatomic的区别
一.三种文件导入的方式比较: 类的前项声明@class.import.include: 1.采用@class 类名的方式,它会告诉编译器有这么一个类,目前不需要知道它内部的实例变量和方法是如何定义 ...
- OBjective-C:atomic和nonatomic的区别
atomic和nonatomic的区别: atomic: 设置成员变量的@property属性时,默认为atomic,提供多线程安全.因为多线程的缘故,所有的对象在操作成员变量时都是同步的,因此,为了 ...
- object-c中的assign,retain,copy,atomic,nonatomic,readonly,readwrite以及strong,weak
assign:指定setter方法用简单的赋值,这是默认操作.你可以对标量类型(如int)使用这个属性.你可以想象一个float,它不是一个对象,所以它不能retain.copy.assign指定se ...
- Objective-C 关键字:retain, assgin, copy, readonly,atomic,nonatomic
声明式属性的使用:声明式属性叫编译期语法 @property(retain,nonatomic)Some *s; @property(参数一,参数二)Some *s; 参数1:retain:修饰引用( ...
- atomic和nonatomic的区别
1.使用atomic进行修饰的属性,在实现文件中不能重写setter方法和getter方法,不然在编译过程会发生报错. 1.使用nonatomic进行修饰的属性,在实现文件中可以重写setter方法和 ...
- iOS 开发 atomic 与 nonatomic 区别
atomic : 变量默认是有该有属性的,这个属性是为了保证在多线程的情况下,编译器会自动生成一些互斥加锁的代码,避免该变量的读写不同步的问题. nonatomic : 如果该对象无需考虑多线程的 ...
- atomic与nonatomic的区别
原子性(atomic):某操作具备整体性,也就是说,系统其他部分无法观察到其中间步骤所生成的临时结果,而只能看到操作前与操作后的结果,那么就称改操作就是“原子的”(atomic),或者说,该操作具备“ ...
随机推荐
- hdu2612.。。。
原题链接 水了一天bfs了 题意:2个人分别从Y,M出发,到达其中任意一个“@” (图中有多个“@”点),2人到达的必须是同一个“@”点,求最短的路程和 思路:bfs搜2次,用一个2维数组记录到达各个 ...
- Ajax请求中的Redirect()
页面中有一个IsLogin()方法,用以判断该请求的触发者是否登录,如果登录了,则执行查询操作,如果没有登录,则Redirect()至登录界面 页面使用了较多的Ajax请求来获取数据,而在Ajax请求 ...
- 面试之servlet、过滤器、监听器
servlet.过滤器.监听器servlet是Java中WEB请求和响应的容器servlet的运行需要在类似tomcat容器中,一个 Web 应用对应一个 Context 容器,也就是 Servlet ...
- 超文本引用href的几种用法
href="要跳转目标链接"; href="#";当前页面不跳转(返回顶部) href="###";当前页面不跳转(同时不回到顶部) hre ...
- Android课程---关于对话框的学习
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- node js 模块分类
核心模块 require('fs'); 核心模块是被编译成二进制代码 文件模块 require('../fs.js'); 对于加载模块时既没指出./ ../ /.../时,加载模块的搜索路径.如果'/ ...
- Boyer-Moore algorithm
http://www-igm.univ-mlv.fr/~lecroq/string/node14.html Main features performs the comparisons from ri ...
- JQuery-文档处理&选择器
<body> <div id="textDiv">...</div> <p>第一段..</p> <b>第二段 ...
- 关于Currency类型和 TCurrencyFiled的悲剧
这2天程序出问题, 用户结算金额经常莫名其妙的多出了小数点后几位, 不用思考 肯定是因为浮点精度不准确的问题 查了一下, 程序中的数据类型使用的是Currency, 按照数据类型的描述, 这个金额类型 ...
- iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案—scrollIntoView()
问题描述 iOS系统下,移动web页面,inpu获取焦点弹出系统虚拟键盘时,偶尔会出现挡住input的情况,尽管概率不大,但是十分影响用户体验. 问题重现 原始页面:页面中有header.main.f ...