Operating System-Thread (2)

Source: Internet
Author: User

Operating System-Thread (2)
This article mainly introduces Thread model 1, Multi-Process-Parallel vs Multi-Thread-Parallel Multi-Process Parallelism: the CPU switches between multiple processes, the system gives an illusion that multiple processes are executed in parallel. Multi-thread parallel: the CPU switches between multiple threads, and the system gives the illusion that multiple threads are executed in parallel. A process is the basic unit for resource allocation, and a thread is the basic unit for CPU execution. II. The previous article mentioned that the threads of the same process share the resources of the process. The thread introduced in the process is to allow multiple executions (threads) share resources and coordinate the tasks. However, each thread has its own exclusive attribute, as shown in figure. The most important thing is stack. Shows the stack. The stack guarantee of the thread has been called but no program has been returned (the reason why recursion wastes resources is that a large number of program calls are stored in the stack of the running thread ). Stack is used to save execution history. Assume that program A calls program B and program B calls program C and C calls program D. When program D is executed, the data in the stack should be ABCD. After program D is executed, D will go out of the stack, and so on. After A executes and returns, the data on the stack will be cleared. 3. Create a New thread when a process starts, the process contains at least one thread, which can be called by the system to create a new thread, to create a new thread, you only need to specify the method (Procedure) to be executed by the thread, instead of specifying the address space of the new thread, because the new thread will automatically run in the address space of the created thread (that is, the address space of the process ). The created thread can be called a subthread, but hierarchy between threads is not very important.

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.