0
votes

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)

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

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.

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.

1
I'm voting to close this question as off-topic because it is asking about terminology, not code. - Daniel A. White
@DanielA.White where should I be posting this then? I don't think this is only about terminology! - Tony Lin
Number of cores does not matter. Multiple processes or multiple threads can run on a single core or on multiple cores. The difference essentially is that the processes are completely independent from each other using their own memories, whether threads share the same memory. - Serge
@Serge Thank you for commenting! I have the same understanding with your points. But if you look at the highlight I got with that article, does it still hold true for 'multiprocess' though? - Tony Lin
The highlight is not correct. Multiple cores allow you to run some processes or threads simultaneously timewise. Otherwise OS will schedule their run by some scheduling algorithm. Think of an operating system (e.g., windows) which runs hundreds of the processes sumulanously just on a few cores (just open the task manager). - Serge

1 Answers

1
votes

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.

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.

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.