多处理与多线程的误解? [英] Multiprocessing vs multithreading misconception?

查看:45
本文介绍了多处理与多线程的误解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以我的理解,多线程是指在一个进程下,包含指令、寄存器、堆栈等的多个线程,1、在单线程/核心cpu设备上并发运行2、在多核cpu设备上并行运行(仅以10核cpu上的10个线程为例)

From my understanding, multithreading means under one process, multiple threads that containing instructions, registers, stack, etc, 1, run concurrently on single thread/core cpu device 2, run parallelly on multi core cpu device (just for example 10 threads on 10 core cpu)

我认为多处理意味着不同的进程在多核 cpu 设备上并行运行.

And multiprocessing I thought means different processes run parallelly on multi core cpu device.

今天读完一篇文章后,我开始思考是我错了还是文章错了.

And today after reading an article, it got me thinking if I am wrong or the article is wrong.

https://medium.com/better-programming/is-node-js-really-single-threaded-7ea59bcc8d64

多处理是使用两个或多个 CPU(处理器)在单个计算机系统中.现在,由于有多个处理器可用,多个进程可以同时执行时间.

Multiprocessing is the use of two or more CPUs (processors) within a single computer system. Now, as there are multiple processors available, multiple processes can be executed at a time.

和运行在多核cpu设备上的多线程进程不一样吗??

Isn't it the same as a multithreading process that runs on a multi core cpu device??

我错过了什么?或者可能是我没有完全理解多处理.

What did I miss? or maybe it's me not understanding multiprocessing fully.

推荐答案

Multiprocessing 是指按照操作系统的调度算法运行多个进程.现代操作系统使用一些时间共享的变体来以伪并行模式运行用户进程.在存在多个 CPU 的情况下,操作系统可以利用它们并以真正的并行模式运行一些进程.

Multiprocessing means running multiple processes in accordance to the operating system scheduling algorithm. Modern operating systems use some variation of time sharing to run user process in a pseudo-parallel mode. In presence of multiple cpus, the OS can take advantage of them and run some processes in real parallel mode.

与线程相比,进程在内存和其他进程上下文方面彼此独立.他们可以使用进程间通信 (IPC) 机制相互交谈.可以为进程分配共享资源,并需要进程级同步才能访问它们.

Processes in contrast to threads are independent from each other in respect of memory and other process context. They could talk to each other using Inter Process Communication (IPC) mechanisms. Shared resources can be allocated for the processes and require process level synchronization to access them.

另一方面,线程共享相同的内存位置和其他进程上下文.它们可以访问相同的内存位置,并且需要使用线程同步技术(如互斥锁和条件变量)进行同步.

Threads, on the other hand share the same memory location and other process context. They can access the same memory location and need to be synchronized using thread synchronization techniques, like mutexes and conditional variables.

线程和进程都是由操作系统以类似的方式调度的.因此,您提供的报价并不完全正确.您不需要多个 CPU 来进行多处理,但是您需要它们来允许几个进程真正同时运行.可以有与同时运行的内核一样多的进程,但是其他进程也会以分时方式共享 CPU.

Both threads and processes are scheduled by the operating system in similar manner. So, the quote you provided is not completely correct. You do not need multiple cpus for multi-processing, however you need them to allow few processes to really run at the same time. There could be as many processes as cores which run simultaneously, however other processes will share the cpus as well in time-sharing manner.

这篇关于多处理与多线程的误解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆