Operating System-Thread (2), operatingsystem

Source: Internet
Author: User

Operating System-Thread (2), operatingsystem

This topic describes the thread model.

1. Multi-Process-Parallel vs Multi-Thread-Parallel

Multi-process Parallelism: the CPU switches between multiple processes, and the system gives the 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. Dedicated resources of processes and threads

As mentioned in the previous article, threads of the same process share the resources of the process. The thread introduced in the process is to allow multiple execution threads to share resources and coordinate the work to complete the task.

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

After a process is started, it contains at least one thread. This thread can create a new thread through system calling. To create a new thread, you only need to specify the method (Procedure) to be executed by this thread ), you do not need to specify the address space of the new thread, because the new thread runs automatically 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.