What’s the difference between multiprocessing and multithreading?

317 views

What’s the difference between multiprocessing and multithreading?

In: 194

17 Answers

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.

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

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

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

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

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

Old OSs like DOS would run only one app, you would run it, work in it and close it to work with another app. Modern OSs can run multiple apps (processes) at the same time hence the name multiprocessing. This is how you can run a browser and excel together. They can’t directly communicate, unless they are designed to do so (this part is oversimplified and omits many things like debuggers and viruses), or user decides to transfer some data between them (copy paste for example)

Now, every application has a thread, in apps with a user interface it is called GUI thread. This thread receives mouse, keyboard, and all possible input from the OS, processes them, and displays results in GUI thread. What you see as applications are actually threads running.

Everything is ok, every application is running smoothly but you decided to download a file in the browser, an it froze because it has one thread and that single thread has to wait the download to finish so it can do other things like respond to cancel download button. It cannot even draw its page or menu or anything really, its single thread is busy downloading the file. Only if there was a way to download it while keeping GUI thread free. Someone said let’s create another thread in this process for other tasks, so GUI thread can work stress free. Processes can create and terminate threads as they please, but if GUI thread is terminated, app is closed. Also threads can communicate with each other since they are in the same app.

In this sense you can think processes as restaurants. A single business entity with multiple workers so each worker can work on a different aspect of the business.

Anonymous 0 Comments

Using the kitchen analogy:

– Multithreading would be doing multiple recipes (or the same recipe multiple times if we are talking about the same code) on a single kitchen. If you need to share stuff between the recipes, you can just take it from the oven/counter, you just need to be careful not to pick up stuff that is unfinished

– Multiprocessing (several processes) would be akin to having several kitchens, if you need to pass ingredients/results, you’d need to use a window between them. A cook in one kitchen does not have direct access to the stuff on the other kitchen, and you probably wont pass unfinished stuff, but it also means that someone in one kitchen has to wait until something is available on the window so that it can be picked up.

– A processor is a cook, so you could technically have a single cook working on two recipes in the same kitchen (Multithreading with a single processor) in which case he needs to jump from one task to the other. You could also have multiple processes in a single processor environment, and in this case the cook needs to leave the whole kitchen and go to the other one in order to execute a different process. Now if you have two cooks in two kitchens, it’d be as two processes running on separate processors, but then there is overhead on communication between them. It all depends on how you assign work to each of the chef/kitchen combinations

Anonymous 0 Comments

You’re taking about two somewhat different concepts.

(1) Multiprocessor v. Uniprocessor

Recall the allied effort to break German codes in WWII? They’d have a room full of people doing a lot of math. That’s like multiprocessing — a bunch of people doing things all at the same time. They may not all be doing the same thing, but they’re all working at the same time.

The contrast is uniprocessing, where you only have ONE person doing something at once.

(2) Multithreading v. Single-threading

Threading is, basically, how many tasks are going on more/less at the same time. You can have multiple things going on either with just one person or with multiple people.

With just one person, that person does some work, gets interrupted to do something else, then switches to a third task, then returns to the first task. For example: Frieda is doing the family taxes, but when the washing machine buzzes, she stops doing the taxes temporarily and goes in to move the wash to the dryer, then returns to the taxes. Or, maybe she decides “I’m going to do my taxes for 30 minutes. Then I’ll call my friend Suzi for 30 minutes. Then I’ll go back to the taxes.”

If you have multiple people working, then you might not need to interrupt Freida. Maybe her husband Larry takes care of the wash or calls Suzi while Frieda does the taxes.

Now, technically, when you’re talking about multithreading in a computer, all of the instructions for doing those things (the taxes, talking to Suzi and swapping the wash) would live inside a single computer program. If they’re in different computer programs, then it’s usually called “multi-process” or “single-process,” but the idea is basically the same.