Tony Lin
Tony Lin

Reputation: 942

Multiprocessing vs multithreading misconception?

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.

Upvotes: 0

Views: 115

Answers (1)

Serge
Serge

Reputation: 12384

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.

Upvotes: 1

Related Questions