Step 0 IOS Multithreading

Source: Internet
Author: User
<span id="Label3"></p>Multithreading Basic Concept Process <ul> <ul> <li>A process is an application that is running in the system</li> <li>Each process is independent, and each process runs within its dedicated and protected memory space</li> <li>by <code>活动监视器</code> enabling you to view the processes that are <code>Mac</code> open in the system</li> </ul> </ul>Thread <ul> <ul> <li>The process must have a thread to perform the task, and the process should have at least one of the threads</li> <li>Program startup opens a thread by default, which is called <code>主线程</code> or<code>UI 线程</code></li> <li>A thread is the basic unit of execution of a process, and all the tasks of the process are executed in the threads</li> </ul> </ul>Multithreading <ul> <ul> <li>Multiple threads can be opened in a process, each thread can <code>同时</code> perform different tasks <ul> <li><code>进程</code>Company</li> <li><code>线程</code>Employees</li> <li><code>主线程</code>Boss (first Employee)</li> </ul></li> <li>Multithreading technology can improve the efficiency of program execution</li> </ul> </ul>Multithreading principle <ul> <ul> <li>At the same time, the CPU can only process one thread, and only one thread executes</li> <li><strong>Multithreading is performed simultaneously, in fact, the CPU quickly switches between multiple threads</strong></li> <li>If the CPU schedules threads fast enough, It causes multiple threads to execute concurrently.<code>假象</code></li> <li>If there are too many threads, switching back and forth between multiple threads consumes a lot of CPU resources <ul> <li>The number of times each thread is dispatched is reduced</li> <li>The execution efficiency of the thread will decrease</li> </ul></li> </ul> </ul><p><p></p></p>Advantages and disadvantages of multithreading <ul> <ul> <li>To improve the execution efficiency of the program appropriately</li> <li>Can appropriately improve resource utilization (CPU, memory Utilization)</li> </ul> </ul>Disadvantages <ul> <ul> <li>Open threads need to occupy a certain amount of memory space, if you open a large number of threads, will occupy a lot of memory space, reduce the performance of the program</li> <li>The more threads, the greater the overhead of the CPU on the dispatch thread</li> <li>Programming is more complex: such as communication between threads, multi-threaded data sharing</li> </ul> </ul>Main thread <ul> <ul> <li>The program initiates the creation of the thread, which is known as <code>主线程</code> or<code>UI 线程</code></li> <li>The role of the main thread <ul> <li>Display/refresh UI Interface</li> <li>Handling UI events: <code>点击</code> , <code>滚动</code> , <code>拖拽</code> etc. events</li> </ul></li> </ul> </ul> <blockquote> <blockquote> <p>Note: to be <code>耗时操作</code> executed in a background thread, this will affect the smoothness of the UI and disrupt the user experience</p> </blockquote> </blockquote> <ul> <ul> <li>All network access is a time-consuming operation!</li> </ul> </ul>Multi-threading implementations in iOS <table> <thead> <tr> <th>Programme</th> <th>Introduction</th> <th>language</th> <th>Thread life cycle</th> <th>Frequency of Use</th> </tr> </thead> <tbody> <tr> <td>Pthread</td> <td> <ul> <li>A common set of multithreaded APIs</li> <li>Suitable for unix/linux/windows and other systems</li> <li>Cross-platform \ Portable</li> <li>Very difficult to use</li> </ul></td> <td>C</td> <td>Programmer Management</td> <td>Almost no</td> </tr> <tr> <td>Nsthread</td> <td> <ul> <li>Use more object-oriented</li> <li>Easy to use, direct manipulation of thread objects</li> </ul></td> <td>Oc</td> <td>Programmer Management</td> <td>Occasional use</td> </tr> <tr> <td>GCD</td> <td> <ul> <li>Designed to replace threading technology such as Nsthread</li> <li>Make the most of your Device's multicore</li> </ul></td> <td>C</td> <td>Automatic Management</td> <td>Frequently used</td> </tr> <tr> <td>Nsoperation</td> <td> <ul> <li>Based on GCD (bottom is Gcd)</li> <li>More simple and practical features than GCD.</li> <li>Use more object-oriented</li> </ul></td> <td>Oc</td> <td>Automatic Management</td> <td>Frequently used</td> </tr> </tbody> </table><p><p>Step 0 IOS Multithreading</p></p></span>

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.