Introduction to Multithreading 001------

Source: Internet
Author: User
Tags gcd

4 Basic Concept Synchronization
    • Before writing the program is from top to bottom, from left to right, code execution order
    • 1 threads perform multiple tasks, which are executed sequentially, and 1 threads perform a task at the same time
Asynchronous

Multiple threads can perform multiple tasks "at the same time"

Process
    • Programs that are running on the current computer
    • Each process is independent, and each process runs within its dedicated and protected memory space
    • You can view the processes that are open in your Mac system through Activity Monitor
Thread
    • A process contains one or more threads
    • Threads are the basic unit of program execution, and all tasks in the process are run in the thread
The basic concept of multi-threaded multithreading
    • Multiple threads can be opened in a process
    • Multiple threads are "simultaneously" running
    • Multithreading can improve the efficiency of program execution
Principle of execution

Fast switching threads through the CPU

Feature summary
    • (Single core CPU) at the same time, the CPU can only handle 1 threads, and only 1 threads are executing
    • Fast switching through the CPU
    • Switching time is very short, resulting in "simultaneous" execution of the phenomenon
    • When very many threads are turned on, CPU switching threads consume a large amount of resources resulting in less efficient execution of threads
Advantages and Disadvantages
    • To be able to appropriately mention the execution efficiency of the procedure
    • To improve the utilization rate of resources appropriately
    • Automatic destruction of threads after all tasks have been performed
Disadvantages
    • Open threads need to occupy a certain amount of memory (by default, each thread is a 512KB)
    • If you open a large number of threads, it will take up a lot of memory space, reduce the performance of the program
    • The more threads, the greater the overhead of the CPU on the calling thread
    • More complex programming, such as inter-thread communication, multi-threaded data sharing
Main thread
    • After a program is run, 1 threads are turned on by default, called the "main thread" or "UI thread"
    • The main thread is typically used to refresh the UI interface and handle UI events (e.g., click, scroll, drag, etc.)

Main thread Usage Note

    • Don't put time-consuming operations into the main thread
    • Time-consuming operations can get stuck in the main thread, seriously affecting the smoothness of the UI, giving the user a bad experience with cards
The difference between four-in-the-middle multithreading technology in iOS

manual
  language /th> Thread life cycle Usage frequency
pthread cross-platform POSIX, inconvenient to use c manual almost no
nsthread oc occasional
gcd optimized for multicore performance, easy to use c auto regular
nsopera tion Encapsulation of GCD, object-oriented oc auto regular



Introduction to Multithreading 001------

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.