1. One thread passes data to another thread;
2. After one thread finishes performing an operation, it goes to another thread to perform the operation
The main thread is also called the UI thread, all UI-related operations are put into the main thread, other operations are placed on child threads,
Nsurl *url = [Nsurl urlwithstring:@"Httpgdaga"];
Current time before download Cftimeinterval begin=cfabsolutetimegetcurrent (); NSData*data =[NSData Datawithcontentsofurl:url];
Current time after download Cftimeinterval end=cfabsolutetimegetcurrent (); NSLog (@"%f", End-begin); UIImage*image =[UIImage Imagewithdata:data]; Self.imageView.image= Image;
Calculate the time difference can also use NSDate
NSDate *begin = [NSData Date];
NSData *end = [NSDate Date];
NSLog (@ "%f", [end Timeintevelsincedata:begin]);
Atomic and Nonatomic
Atomic atomic properties, thread safety, call setter method is lock, call after unlock, but consume a lot of resources,
Nonatomic thread is unsafe, does not lock the setter method, is suitable for small memory mobile devices
iOS try to avoid multithreading to rob the same data, the general call setter method is in the main thread, so generally involved in the case of the looting of resources, so the attributes are decorated with nonatomic
iOS recommendations
1, attributes with nonatomic decoration
1. Multiple threads accessing the same resource can cause thread insecurity
2, try to locking, rob the resources of the work to the server processing, reduce the pressure on the mobile phone
Inter-thread communication