Multi-CPU, multi-core, multi-process, multi-threaded

When faced with these problems, there are two key words can not be bypassed, and that is parallel and concurrent .

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. (Sharing of resources allocated to the process)

  When the scheduling process for a single CPU, executes the program needs to read the context + + context saving, 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.

  A thread is CPU scheduling and distribution of basic units , be sure to process 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.

  to sum up:

  1, a single process can only be complicated by the CPU, 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.

 

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

When faced with these problems, there are two key words can not be bypassed, and that is parallel and concurrent .

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. (Sharing of resources allocated to the process)

  When the scheduling process for a single CPU, executes the program needs to read the context + + context saving, 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调度和分配的基本单位,一定要和 进程是操作系统进行资源分配(包括cpu、内存、磁盘IO等)的最小单位 区别清楚。有句话说CPU只能看到线程,可以这么理解,假设我是CPU,我闭着眼,操作系统调度器将一个进程分配给我之后,我拿到进程睁开眼,我看到的是什么?我看到的是进程中的很多线程,那么我现在能调度和分配的是什么?进程?不行,因为我看不到其他进程,何来调度分配,只能调度我看到的那些线程,如果我是4核的话,把线程ABCD分配到核心1234,其他的线程依然要等待分配,至于等待多久,如何分配,暂不在本文讨论范围。于是线程是CPU调度和分配的基本单位。

  最后说一下操作系统内存管理模块这里做的事:在这之前,程序员需要为每个程序安排运行的空间,这里的空间指的是内存的物理地址,但是这么的问题就是,每个程序都要协商如何使用同一内存的不同空间,而且程序员还要关心底层内存分配问题。解决办法就是,提出进程的概念,每个进程用一样的虚拟地址空间,CPU上增加了MMU模块负责转换虚拟地址和物理地址,虚拟地址经过操作系统和MMU之后,虚拟地址会映射到不同的物理地址,不同的进程就能获得各自独立的物理内存空间。

  另外在有的操作系统里,进程不是调度单位,线程是最基本的调度单位,调度器只调度线程,不调度进程,如VxWorks。

  总结:

  1、单CPU中进程只能是并发,多CPU计算机中进程可以并行。

  2、单CPU单核中线程只能并发,单CPU多核中线程可以并行。

  3、无论是并发还是并行,使用者来看,看到的是多进程,多线程。

 

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

Guess you like

Origin www.cnblogs.com/idyllcheung/p/11288772.html