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的更多相关文章

  1. 【iOS atomic、nonatomic、assign、copy、retain、weak、strong】的定义和区别详解

    一.atomic与nonatomic 1.相同点 都是为对象添加get和set方法 2.不同点 atomic为get方法加了一把安全锁(及原子锁),使得方法get线程安全,执行效率慢 nonatomi ...

  2. IOS atomic与nonatomic,assign,copy与retain的定义和区别

    IOS atomic与nonatomic,assign,copy与retain的定义和区别 atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作.        ...

  3. Objective-C:三种文件导入的方式以及atomic和nonatomic的区别

    一.三种文件导入的方式比较:   类的前项声明@class.import.include: 1.采用@class 类名的方式,它会告诉编译器有这么一个类,目前不需要知道它内部的实例变量和方法是如何定义 ...

  4. OBjective-C:atomic和nonatomic的区别

    atomic和nonatomic的区别: atomic: 设置成员变量的@property属性时,默认为atomic,提供多线程安全.因为多线程的缘故,所有的对象在操作成员变量时都是同步的,因此,为了 ...

  5. object-c中的assign,retain,copy,atomic,nonatomic,readonly,readwrite以及strong,weak

    assign:指定setter方法用简单的赋值,这是默认操作.你可以对标量类型(如int)使用这个属性.你可以想象一个float,它不是一个对象,所以它不能retain.copy.assign指定se ...

  6. Objective-C 关键字:retain, assgin, copy, readonly,atomic,nonatomic

    声明式属性的使用:声明式属性叫编译期语法 @property(retain,nonatomic)Some *s; @property(参数一,参数二)Some *s; 参数1:retain:修饰引用( ...

  7. atomic和nonatomic的区别

    1.使用atomic进行修饰的属性,在实现文件中不能重写setter方法和getter方法,不然在编译过程会发生报错. 1.使用nonatomic进行修饰的属性,在实现文件中可以重写setter方法和 ...

  8. iOS 开发 atomic 与 nonatomic 区别

    atomic :  变量默认是有该有属性的,这个属性是为了保证在多线程的情况下,编译器会自动生成一些互斥加锁的代码,避免该变量的读写不同步的问题. nonatomic  : 如果该对象无需考虑多线程的 ...

  9. atomic与nonatomic的区别

    原子性(atomic):某操作具备整体性,也就是说,系统其他部分无法观察到其中间步骤所生成的临时结果,而只能看到操作前与操作后的结果,那么就称改操作就是“原子的”(atomic),或者说,该操作具备“ ...

随机推荐

  1. [LintCode] Reverse Linked List 倒置链表

    Reverse a linked list. Have you met this question in a real interview? Yes Example For linked list 1 ...

  2. [LintCode] Nuts & Bolts Problem 螺栓螺母问题

    Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...

  3. [LintCode] Toy Factory 玩具工厂

    Factory is a design pattern in common usage. Please implement a ToyFactory which can generate proper ...

  4. Tree树形结构案例+源码

    上次用到Tree结构,自己不知道写,就在网上找了几个相对较好的tree小案例,留着自己用,希望也能帮到你 下面是案例的一些图片,压缩文件已近上传至博客当和百度云中. 下载链接:http://pan.b ...

  5. thinkphp类的调用

    1.在controller下新建一个类,类的名称必须按照tp的规范来写. 2.在需要调用的类中,只需new一下被调用的类名. $t=new DataController(); $t->m();

  6. HDU2067/HDU1267 /HDU1130 递推

    小兔的棋盘 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. Oracle常用命令(持续更新)

    --1.解锁用户 alter user 用户名 account unlock; --2.开启最小补充日志记录(执行的DML操作会被记录下来)  alter database add supplemen ...

  8. Mysql忽略文件名的安全编码

    author:skatetime:2014/09/28 mysql如何删除以"#sql-"开头的临时表 现象:在重建索引后,发现Mysql服务器的磁盘空间快满了 在用如下命令重建索 ...

  9. 禁止北京地区IP访问站点

    <script type="text/javascript" src="http://counter.sina.com.cn/ip" charset=&q ...

  10. 【iCore3 双核心板_FPGA】例程七:基础逻辑门实验——逻辑门使用

    实验指导书及代码包下载: http://pan.baidu.com/s/1Rs18U iCore3 购买链接: https://item.taobao.com/item.htm?id=52422943 ...