Multi-thread Journey 2-thread and process Introduction

Source: Internet
Author: User

Process: a data structure for allocating system resources.

In short, like a storage box, a pointer in a process is designed to be inaccessible to other processes to ensure security. Just as your key normally cannot open any one's storage box, you can only open your own storage box. If someone else's storage box is opened, it is not unintentional code negligence, or malicious attacks against other programs.

 

Thread: a data structure for allocating CPU run cycles. A thread is an abstract concept of a task. Creating a thread is equivalent to telling the CPU that you need to allocate time for a new task. The difference between multithreading and executing multiple tasks in one thread is that creating multiple threads requires the cpu to process some tasks at the same time, rather than sequential tasks. In unix, there is no such concept as thread, and there is only the concept of task. A task is equivalent to a process with only one thread. tasks can be combined to indicate that the memory space of the task can be shared to achieve the same purpose similar to multithreading. If a method requires CPU computing, its parameters, local variables, and so on will naturally be stored in the thread. The thread data structure contains a stack structure to store the information, the execution is represented by the inbound and outbound stack. Stack is a thread.
Deadlock: The execution conditions of a task are never met, so the cpu has never been assigned the execution time to the task. Live lock: it constantly takes the cpu time to check whether the task can be executed. Whether it is a deadlock or a live lock, we have to waste the memory space that retains parameters, local variables, and other such information. It can be seen that the active lock is more serious than the deadlock, because in addition to wasting memory space, it also wastes CPU. There is no relation between processes and threads. They are different abstract concepts. A process is not composed of one or more threads. Without threads, process resources cannot be used by the CPU. Therefore, a process should have at least one thread. Otherwise, what is the use of the process? In Win32, a process does not execute anything. It only occupies the address space used by the application. In short, a thread is a way to call resources in a process. But what is the memory address range of a thread stack? The address range of the thread stack is one of the addresses occupied by the process of the thread. The preceding figure shows the relationship between threads and processes. Although the thread Stack has a continuous memory within the address range of the process, you can think that the thread stack belongs to the thread and has nothing to do with the process. The data stored in the stack only indicates what the cpu will do next. In a sense, a thread can be considered as a virtual processor. Each thread runs part of the code in the program and shows that it is irrelevant to other virtual processors in the system.

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.