1: original from: http://www.cocoachina.com/bbs/read.php? Tid = 42551
I assign values to many attributes in the dootherfunc function called by the subthread. These attributes are defined as @ property (nonatomic, retain )."Nonatomic multithreading related ~ Writing without multithreading can improve efficiency"Now I have multiple threads, right? Can't we improve efficiency? The relationship between attributes defined as nonatomic and multithreading is not too clear. Which of the following experts will explain the relationship! Thank you!
the default attribute we define is atomic, it means that you need to add a lock operation before accessing these attributes, and then add the unlock operation after the access, so as to avoid some unknown problems caused by simultaneous access in different threads.
if this is not added, for example, two subthreads run simultaneously, if you modify the value of an object in the first thread or release the object, the second thread may get an incorrect value, or the Program crash is generated because the object is being used but is dropped by the first thread relase.
the lock and unlock may cause system consumption, if we determine that we will not use the attributes in different threads at the same time, we can define them as nonatomic to reduce system consumption. If we may access them in different threads, use atomic, or do nothing (because atomic is the default ).