Locking
@synchronized (self) {
At the same time, only one thread can execute, but very expensive source
}//Unlock
About the lock, here's a thing. About this syntax: @property. Each time we define a property, we will be the first to write the nonatomic, which is why? Please see the following explanation:
The difference between nonatomic and atomic in @property:
All know, these two keywords represent the same thing, but the meaning of the representative is different. is thread-related.
Nonatomic represents: Threads are unsafe.
Atomic stands for: threads are safe.
So, here's the question. What is the concrete manifestation of security and insecurity? is actually whether to give this attribute setter method whether lock.
Nonatomic stands for: there is no lock on the setter method for this property, so it is unsafe.
Atomic represents: The setter method of this property is locked, so it is safe.
So, here comes the question again. Why should we recommend using Nonatomic in our iOS development?
This problem should start with the depletion of resources. In iOS development, the invocation of setter methods is very frequent. It is very resource-intensive to lock the setter method. So on mobile devices, use nonatomic as much as possible. In MAC development, it is usually the use of atomic. If you care about security issues, there is no problem with using atomic.
iOS cable Cheng