Several Concepts of multithreading in OC

Source: Internet
Author: User

1. Process
1.1> process refers to an application running in the system. (when both QQ and Xcode are enabled, the system starts two processes respectively)
1.2> each process is independent, and each process runs in its dedicated and protected memory space.

2. threads
1.1> A process must have a thread (each process must have at least one thread, that is, the main thread) to execute a task)
1.2> A thread is the basic execution unit of a process. All tasks of a process are executed in the thread.
3. Multithreading
3.1> multiple threads can be enabled in a process, and each thread can execute different tasks in parallel (at the same time ).
Process → workshop, thread → Workshop worker
3.2> multithreading technology can improve program efficiency
4. multithreading Principle
4.1> at the same time, the CPU can only process one thread, and only one thread is working (executed)
4.2> multi-thread concurrent (concurrent) execution is actually a fast CPU scheduling (switching) between multiple threads)
4.3> If the CPU scheduling thread time is fast enough, it creates the illusion of multi-thread concurrent execution.
5. Advantages and Disadvantages of Multithreading
5.1> advantages of multithreading:
(1) appropriately improving program execution efficiency
(2) appropriately improving resource utilization (CPU and memory usage)
5.2> multithreading disadvantages:
(1) enabling a thread requires a certain amount of memory space (by default, the main thread occupies 1 M, and the sub-thread occupies KB). If a large number of threads are enabled, it will occupy a large amount of memory space and reduce program performance.
(2) The more threads, the higher the CPU overhead on the scheduling thread.
(3) More Complex Program Design: for example, inter-thread communication and multi-thread data sharing
6. main thread
6.1> after an iOS program runs, one thread is enabled by default, which is called "main thread" or "UI thread"
6.2> main functions of the main thread
(1) display \ refresh the UI
(2) handling UI events (such as click events, rolling events, and drag and drop events)
6.3> main thread usage notes
(1) do not put the best operations in the main thread.
(2) The operation will be stuck in the main thread, seriously affecting the smoothness of the UI, giving users a "card" Experience
7. multi-thread implementation solution

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.