The basic concept of multithreading

Source: Internet
Author: User
Tags gcd

1 Basic Concepts
01 ProcessA process is an application that is running in the system. Each process is independent, and each process runs within its dedicated and protected memory space.

02 Threads2-1 Basic Concepts 1 processes to perform a task, you must have a thread (at least 1 threads per 1 processes), which is the basic execution unit of the process, and all tasks of a process (program) are executed in the thread.
The execution of a task in a 2-2-thread serial 1 thread is serial, and if you want to perform multiple tasks in 1 threads, you can perform these tasks sequentially, one by one. That is, within the same time, 1 threads can only perform one task.
03 Multi-Threading3-1 The basic concept is that multiple threads can be opened in 1 processes, and each thread can perform different tasks in parallel (at the same time). Parallel parallelism of 3-2 threads is performed concurrently. For example, open 3 threads to download 3 files respectively (file A, file B, file C, respectively).
3-3 multi-threaded concurrent execution principle at the same time, the CPU can only handle 1 threads, and only 1 threads are working (executing). Multithreading concurrency (at the same time) execution, in fact, the CPU is quickly dispatched between multiple threads (switching), if the CPU scheduler thread time is fast enough, resulting in multi-threaded concurrent execution of the illusion of 3-4 multi-threading advantages and disadvantages 1) can properly improve the execution efficiency of the program. 2) can appropriately improve resource utilization (CPU, memory Utilization) disadvantage 1) The open thread needs to occupy a certain amount of memory space (by default, the main thread takes up 1M, the child threads occupy 512KB), if you open a large number of threads, will consume a lot of memory space, reduce the program's Performance. 2) The more threads, the more overhead the CPU will have on the dispatch thread. 3) more complex programming: such as communication between threads, multi-threaded data sharing04 Multi-threading applications in iOS development4-1 main thread 1) after an iOS program runs, the default is to turn on 1 threads, called the main thread or the UI thread. 2) effect. Refreshes the display UI and handles UI events. 4-2 use note 1) do not put the time-consuming operation in the main thread to process, will be stuck thread. 2) and UI-related refresh operations must be placed in the main thread for processing.Multi-Threading implementations in iOS5-1 pthread A. Features: 1) A set of common multithreaded API 2) for Unix\linux\windows and other systems 3) cross platform \ Portable 4) difficult to use B. Language used: C language C. Frequency of use: almost no d. Thread life cycle: Managed by programmer 5-2 Nsthread A. Features: 1) Use more object-oriented 2) Easy to use, directly manipulate thread object B. Language: OC language C. Frequency of use: occasional use of D. Thread life cycle: Managed by programmer 5-3 GCD A. Features: 1) designed to replace N Sthread and other Threading Technology 2) make full use of the device's multicore (automatic) B. Language: C language C. Frequency of use: frequently used D. Thread life cycle: Automatic Management 5-4 nsoperation A. Features: 1) based on gcd (bottom is GCD) 2) than GCD a few more simple and practical functions 3) Use more object-oriented B. Language: OC language C. Frequency of use: often Using the D. Thread life cycle: automatic management

The basic concept of multithreading

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: 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.