Multi-threading or multi-processing, how to know which to use and when?

Generally speaking, multithreading is more light-weigt than multiprocessing. It’s cheaper to start a thread than a process and as a user you don’t have to get into the @everywhere business. So if you’re not concerned about distributed computing involving multiple machines, multithreading should likely be your first choice. However, what I like about Distributed is that processes are “very much separate” conceptually and actually. For this reason, one typically doesn’t run into race conditions that easily (they can still exist of course).

Unless you explicitly pin threads or processes, you shouldn’t make any assumptions about on which core a certain thread or process will run. The OS can move threads and process around. (In fact, on macOS you can’t even pin at all!)

Well, both multithreading as well as multiprocessing give you parallelism. I guess I don’t understand the question?

6 Likes