What’s the difference between multiprocessing and multithreading?

322 views

What’s the difference between multiprocessing and multithreading?

In: 194

17 Answers

Anonymous 0 Comments

Something to keep in mind here:

These things can work differently on different platforms and languages.

If you’re learning programming on Windows with C#, you’re going to learn the Windows and C# way of doing things.

If you later learn to write server software in Go and run it on Linux, you’ll have to learn the Linux and Go ways of doing things.

If you write phone apps for Android in Kotlin, you’ll have to learn the Android and Kotlin ways of doing things.

This affects things such as:

* How fast or slow is it to start a new process or thread?
* How can processes or threads communicate with each other?
* Are there special kinds of process or thread with special rules?
* What exact terminology do programmers use for these things?

Anonymous 0 Comments

I think the answers here are either wrong, incomplete, or too complex for an ELI5. Some notes: (1) ELI5’s don’t always have to use analogies, (2) people are forgetting to even explain *what* is a process.

Here’s my attempt. I’ll include a third term *multitasking* because it is too closely related:

A **process** is a program (e.g., an app) running. You have Word running on your laptop? That’s a process. You have Candy Crush running on your phone? That’s a process. The fact that you can have more that one program running at once on one processor core is **multitasking**. That includes running two instances of the same program. You have two instances of notepad.exe open? That’s two processes—a multitasking in action. How can there be multiple processes running on one processor core? The trick is that the processor can actually only run one process at a time, but switches back and forth between several program instructions very rapidly to make it seem like it’s doing everything all at once.

In today’s computers you rarely only have one processor core. When you have multiple processor cores, your computer can actually *physically* run more than one processes at the same time. That is, up to the number of cores it has. This is what we call **multiprocessing**. Imagine at one instance of time, CPU core #1 is running Word program, core #2 is running Excel, and #3, Notepad.

Now, within a process, again, your CPU core can only actually do one thing at a time. For example, when it is busy rendering video to your screen, it cannot at the same time be listening to an input event, e.g., keyboard key press or mouse click. So how can you click the pause button on your media player app and have it actually register the click and pause the video playback? Again, the CPU switches back and forth rapidly between rendering video and listening to mouse click events. In contrast to the previous example (running two processes at the same time), the two activities happen within a single process. To achieve this, there are actually two separate **threads** running within the media player process. One for rendering the video, and one for listening to mouse click events. These threads have access to all the process’ resources. This is called **multithreading**. Now whenever you see that UI elements (buttons, etc.) of an app are not responding to your clicks while the app’s doing some other thing, you know that the app developer did not implement multithreading as god intended.

Edit: granted, this is not quite an ELI5, but I think this is as close as I can get, as I think a real five-year-old would not come up with this question. I think my answer only requires a very basic experience in using a computer and knowing that there’s a thing called a processor (core) inside a computer to be understood.

Anonymous 0 Comments

Think of a process as a mouth eating and a thread as a hand feeding the mouth.

Multiprocessing is like multiple mouths eating and multithreading are like 2 hands queuing food into the mouth (process)

Anonymous 0 Comments

I thought multi-threading was taking a single large process and splitting it into multiple processes to speed up the overall process. I know when working in the mainframe days, a difference between the CDC and Cray processors was the Cray was better at multi-threading. My cousin worked on a project that was able to take programs not written to multi-thread but would make them able to multi-thread.

Anonymous 0 Comments

From my understanding a process is a program in execution. Where multiprocessing is where a processor is executing multiple programs though not necessarily in parallel since programs can be time multiplexed on a single processor.

Multithreading is similar but like one abstract layer up where parts of a program can be broken up into pieces called threads which are given time on a processor/processors. These threads, being part of the same program can share resources more readily among threads of the same program.

Both multithreading and multiprocessing are used to give a sense of improved performance since many programs and parts of programs are I/O dependent among other things.(Like imagine the millions of CPU cycles wasted if your computer was just waiting for a keyboard input when it could be used updating what you see in your screen).

Anonymous 0 Comments

Multiprocessing splits up a task into multiple pieces that can be processed simultaneously by multiple cores. This can improve performance if the computer has multiple cores and the tasks can be divided up in a way that takes advantage of that.
Multithreading is a form of multiprocessing where each task is assigned to its own core, but all cores share a single memory space. So multithreading is better for tasks that can be broken down into smaller parts and don’t require a lot of communication between threads. If the tasks do require communication, then multiprocessing might be a better option.

Anonymous 0 Comments

The difference between juggling and playing catch with someone else.

You can also play catch while juggling.

The balls would represent the tasks.
A person would be a process and hands would be the threads.

A typical processor (playground) can hold 4-8 people (or octopuses) that can juggle and play catch.