What’s the difference between multiprocessing and multithreading?

332 views

What’s the difference between multiprocessing and multithreading?

In: 194

17 Answers

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

You are viewing 1 out of 17 answers, click here to view all answers.