Multithreading Basics (V)

Source: Internet
Author: User

5, multi-threaded basis

inter-thread communication What is called inter-thread communication in a process, threads often do not exist in isolation, and multiple threads need to communicate between threads frequently 1 threads pass data to another thread after performing a specific task in 1 threads,
    • The embodiment of inter-thread communication
    • 1 threads to pass data to a different 1 a thread
    • in the 1 after performing a specific task in a thread, go to another 1 threads continue to perform tasks
 Common methods for inter-thread communication perform execute selector selector- (void)Performselectoronmainthread:(SEL)AselectorWithobject:(ID)ArgWaituntildone:(BOOL) wait;- (void)Performselector:(SEL)AselectorOnthread:(Nsthread*)THRWithobject:(ID)ArgWaituntildone:(BOOL) wait;The above two methods are object methods, and objects that inherit nsobject can be used. Code (for example, to load a picture on a network) Here first to a network image download address, pretty HD pictures OH: URL:http://g.hiphotos.baidu.com/zhidao/pic/item/42166d224f4a20a4884b622491529822730ed0f8.jpgBefore hitting the code, add a setting in the Info.plist project file because since Xcode 7.0, it is necessary to manually add the Settings app Transport Security settings to the Info.plist file from the network. Operations that do not use multithreading below we need to take some steps to get the time of the execution of a piece of code
    • The first of these methods
    • The second method of
Then cut to the chase and send the message to the main thread in the child threads, also two methods:
    • Method One
Note that the above code uses the Nsthread sleep method to get it asleep for 3 seconds.
    • Method Two
About this third method, you can look at my summary, and then basically can be achieved without looking at the source code to quickly self-knock out:

Multithreading Basics (V)

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.