Inter-thread communication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.