What’s the difference between multiprocessing and multithreading?

318 views

What’s the difference between multiprocessing and multithreading?

In: 194

17 Answers

Anonymous 0 Comments

A thread is just a single stream of instructions that a programme intends to run. Threads run in a kind of time-share on the same processor. You can run multiple threads on a single processor. You use threads for, for example, one thread drawing the graphics while another handles the physics while another caters for the user’s inputs, etc. That way multiple things can happen at the same time and make full use of the available resources rather than having to wait one after the other. The processor gives each thread a small amount of time to do its thing, then moves on to the next thread, so each thread gets a fair share and everything “progresses” in small snippets of time.

“Multiprocessor” systems actually have entire extra full processors. This used to be called SMP. You would literally have two or more processor slots on the motherboard and two or more main processors. This is still true in servers and high-end configurations

Nowadays the line is blurring as a single physical processor can contain multiple processor cores on the same physical die (e.g. “dual core”) – so it acts like a multiprocessor system, and each of those processors is also capable of handling many threads (Intel sell this as “hyperthreading” in some instances). The same few threads that the programmers request may well be running on entirely different processors, or all on the same one.

In the grand scheme of things, you want as many processor cores as possible, and whether they are on the same processor largely doesn’t matter. Each of those processors you want handling as few threads as possible, but you also need it to be able to handle LOTS of threads – hundreds or more.

And programmers – pretty much don’t care now. They program in threads and the operating system and hardware sorts out what thread runs on what core which is on what chip, and depending on the machine, it makes the best use of the available hardware. That might mean 1000 threads all running on one processor core to save power or because you don’t have extra processors, or 1 thread running on a processor core all on its own to get the entire use of the processor for that one important thread.

But multiprocessors are like owning several apartments. Multithreading is like letting out those apartments on a timeshare. If you have 1 apartment and 50 people sharing it, each person only gets a small amount of time to do what they need to do – so it’s “slow”. If you have 12 apartments (cores) and you have 24 people (threads) sharing them, each one gets a lot more time to do what they need to do, so it’s “faster” and more people (threads) are happier than if they were all sharing the same apartment.

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