Introduction to multithreading and nsunloop in IOS

Source: Internet
Author: User

Thread Overview

For example, if Hello World is run and printed, its life cycle ends. Some programs are a circle that keeps repeating until it is cut off, such as the operating system, until you shut down.

Create thread

 [myObj performSelectorInBackground:@selector(doSomething) withObject:nil]; 
  

Multithreading 

The thread application in the iPhone is not uncontrolled. Official documents show that the stack size of the main thread in the iPhone OS is 1 MB, and that of the second thread is kb at the beginning. The value cannot be changed through the compiler switch or the thread API function. Only the main thread can directly modify the UI.

- ()setMaxConcurrentOperationCount:(NSInteger)count 

Inter-thread Communication

1. datagmselect On The Thread


RunLoop


There are two types of events to be processed: one is the input source and the other is the timer.,Input SourceTransmits asynchronous events. messages are generally sent from other threads or programs.Scheduled sources are the operations that require scheduled execution,Transfer a synchronization event at a specific time or repetition interval. Both origins use a specific processing routine of the program to process events that arrive.There are three types of input sources: performSelector source, Mach port-based source, and custom source.You can add your own source when programming. RunLoop also has the concept of Observer. You can add your own Observer to RunLoop to monitor the running process of RunLoop.

 

By default, RunLoop of non-main threads does not run. You need to add at least one event source for RunLoop.And then run it. Generally, we do not need to enable the RunLoop of a thread unless you need to detect an event for a long time in a separate thread.

Related Article

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.