Conceptual understanding: multi-CPU, multi-core, multi-process, multi-threaded

Reference article: https://www.cnblogs.com/csfeng/p/8670704.html

When faced with these conceptual issues, there are two key words can not be bypassed, and that is parallel and concurrent. I understand: Concurrency refers to parallel the macro, in fact, not parallel, for example, multi-process is the fact that all processes into a time of a time slice, each time only to perform the operation piece, turn back time slice expires the next time slice execution process.

First of all, we must first understand a few concepts:
  1, a process is executing a program.
  2, the process is the basic unit (scheduling unit) resource allocation.
  3, a process can include multiple threads.
  4, in a single CPU computer, there is not a resource used by a plurality of parallel programs: CPU.
  5, the operating system scheduler: Split CPU chip running for some time already, the turn assigned to different procedures.
  6, the operating system memory management module: management of physical memory, virtual memory-related matters.

Since the CPU can only execute a process with time, if we are not controlled, it is possible to use a process CPU until the end of the run, so there is a operating system scheduler, and the process has become a dispatch unit.
  Running processes requires not only CPU, but also a lot of other resources, such as memory ah, ah card, GPS, ah, ah disk, etc., collectively referred to as the execution environment program, which is the application context.
  Here arises the concept of concurrent scheduler switching speed of the CPU to use different processes are very fast, so it seems in the user program is running at the same time, this is complicated by, while CPU is actually running at the same time only one process .
  The process can not share the same CPU time, but we must appear to share the CPU needs it? At this time, the concept of threads emerged. Thread is included in the process among different threads of a process share the CPU and program context. (The process of sharing resources allocated)
  time for a single CPU scheduling process, it is necessary to read context save + + program execution context, i.e., the process of switching.
  If this is a single-core CPU, then the different threads in the process in order to use CPU core, it will be a thread switch, but due to the shared program execution environment, the thread switching process switching overhead than a lot less. Here it is still complicated by the only core the same time can only execute one thread.
  If this is a multi-core CPU, then the process in different threads can use different core, true parallel appeared.
  
  CPU thread scheduling and allocation is the basic unit must process and the operating system allocates resources (including cpu, memory, disk IO, etc.) is the smallest unit of difference clear. There is a saying CPU can only see the thread, so to understand, I suppose CPU, I close my eyes, the operating system scheduler will assign a process to me after I got the process opened his eyes, what I see? I see many threads in the process, then what I now scheduling and allocation is? process? No, because I see no other process, how to schedule the distribution, scheduling those threads I can see, if I was a 4-core, then the thread assigned to the ABCD core 1234, other threads still have to wait for allocation, as the wait how long, how to allocate, they will not in the scope of this article. Then the CPU thread scheduling and allocation of the basic unit.
  
  Finally, talk about the operating system memory management module here to do: Before this, programmers need to arrange for space to run each program, space here refers to the physical address of the memory, but such a problem is that each program how to negotiate the use of the same memory space is different, but programmers should care about the underlying memory allocation problem. The solution is to put forward the concept of the process, each process using the same virtual address space, the CPU adds MMU module converts virtual addresses and physical addresses, virtual address after the operating system and MMU, virtual addresses are mapped to different physical address, different processes can be obtained independently of the physical memory space.
  Also in some operating systems, the process is not scheduling unit, the thread is the basic unit of scheduling, the scheduler schedules threads only, not the scheduling process, such as VxWorks.
  
  Summary:
  1, Single CPU in the process can only be concurrent, multi-CPU computer can process in parallel.
  2, a single core single CPU thread can concurrently, a single multi-core CPU in the parallel threads.
  3, either concurrent or parallel, the user point of view, see the multi-process, multi-threaded.

Guess you like

Origin blog.csdn.net/weixin_40407893/article/details/91412187