<span id="Label3"></p><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong><span style="font-family: ‘Microsoft YaHei‘;">Basic concepts of the Process:</span></strong></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">1. Each process is an application, and there is a separate memory space, in general, a process exists in one application, but there are multiple processes. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2. Threads in the same process share in-memory resources in Memory. </span></span><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong><span style="font-family: ‘Microsoft YaHei‘;">the basic concept of multi-threading:</span></strong></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">1. Each program has a main thread, which is created when the program starts (call the main function to Start)</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2. The main Thread's life cycle is bound to other applications, and when the program exits, the main thread stops. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">3. Multithreading technology indicates that an application has multiple threads, and using multithreading can improve the efficiency of CPU usage and prevent thread blocking</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">4. Any task that is likely to block the main thread does not execute in the main thread (for example, network Access)</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong><span style="font-family: ‘Microsoft YaHei‘;">thread usage is not uncontrolled:</span></strong></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">the <span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">stack size of the main thread in 1.iOS is 1M</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2. Starting with a second thread is 512KB</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">3. These values cannot be changed by the compiler switch or the thread API function</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">only the main thread has the ability to directly modify the Ui. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong><span style="font-family: ‘Microsoft YaHei‘;">three types of multithreading technology for Ios:</span></strong></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">1.NSThread Each Nsthread object corresponds to one thread, lightweight. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2nsoperation/nsoperationqueue object-oriented Threading Technology. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">3.gcd--grand Central Dispatch is a c-based framework that makes full use of multicore and is also an official recommended multithreaded technology by Apple. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><strong><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14pt;">Comparison of three multithreading techniques:</span></strong></strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">1.NSThread: pros: Nsthread is lighter than the other two and is easy to use. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">cons: you need to manage your Thread's lifecycle, thread synchronization, locking, sleep, and wake up. Thread synchronization has a certain overhead in locking data</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2.NSOpertion: no need to care about thread management, data synchronization, You can focus on what you need to do. Nsopertion is Object-oriented. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">3.GCD:GCD is a multi-core programming solution developed by Apple. Ios4.0+ can be used as an alternative to Nsthread,nsoperation's efficient and powerful technology, GCD is based on the C language</span></span><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">GCD is Apple's solution for multi-core parallel computing</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">GCD will automatically take advantage of more CPU cores (such as dual-core, quad-core)</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">GCD automatically manages the life cycle of threads (create threads, schedule tasks, Destroy Threads)</span></p></p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">programmers just need to tell gcd what tasks they want to perform, without having to write any thread management code</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">there are two core concepts in Gcd:</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(1) task: What action to perform</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(2) queue: Storage Task</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><strong> </strong></span></span><strong><strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 14pt;">queue:</span></strong></strong><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><br>1. Serial Queue: The task that is added to the queue is a single execution<br><br>2. Parallel (outgoing) queue: Tasks added to the queue are multiple simultaneous executions<br><br>3. Home Column: The tasks inside are performed on the main thread, which can be understood as the main queue is a serial queue<br><br>4. Global queue: parallel (outgoing) queue</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong><span style="font-family: ‘Microsoft YaHei‘;">synchronous, asynchronous:</span></strong></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">1, synchronization: need to wait for the later task, will not open a new thread, will be directly using the current thread<br></span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">2, async: do not need to wait for the later task, will open a new thread</span></span><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(1) perform the task Dispatch_sync (dispatch_queue_t queue, dispatch_block_t Block) in a synchronous manner;</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Parameter description:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">queue: queues</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Block: Task</span></p></p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(2) Execute the task Dispatch_async asynchronously (dispatch_queue_t queue, dispatch_block_t block);</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">3. The difference between synchronous and asynchronous</span></span><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Synchronization: executing in the current thread</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Async: executing in another thread</span></p></p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">description:</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">The synchronization function does not have the ability to open threads, no matter what queue does not open the thread, the asynchronous function has the ability to open threads, open a few threads by the queue (the serial queue will only open a new thread, the concurrent queue will open multiple threads). </span></span><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Synchronization functions</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(1) Concurrent Queue: No thread</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(2) Serial Queue: No thread</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">Asynchronous functions</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(1) Concurrent queue: can open n threads</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">(2) serial queue: Open 1 threads</span></p></p><p><p></p></p><p><p></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="line-height: 1.5;">In all functions, the names of functions, such as create\copy\new\retain, need to be release when the data is not Needed.</span></span></p></p><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">the <span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">GCD data type does not need to be release in the Arc Environment. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">the <span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">data type of the CF (core Foundation) is still required for release in the Arc Environment. </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;">asynchronous functions have the ability to thread, but not necessarily the thread</span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"><span style="font-family: ‘Microsoft YaHei‘; font-size: 15px;"> </span></span><p><p>IOS Multithreading Knowledge Summary GCD Basics</p></p></span>
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