Multithreading and multicore differences Multithreading and multicore differences multithreading multithreading

Multithreading and multicore differences


Firstly is there a difference between multithreading and multicore?

Yes.

Multithreading and Multicore are different pieces of terminology that apply to different areas of computing.

  • Multicore refers to a computer or processor that has more than one logical CPU core, and that can physically execute multiple instructions at the same time. A computer's "core count" is the total number of cores the computer has: computers may have multiple processors, each of which might have multiple cores; the core count is the total number of cores on all of the processors.

  • Multithreading refers to a program that can take advantage of a multicore computer by running on more than one core at the same time. In general, twice as many cores equals twice as much computing power (for programs that support multithreading) though some problems are limited by factors other than CPU usage; these problems will not experience gains that are as dramatic from multithreading.

    It's important to note that performance is not the only reason programs use many threads. More on that later.

Are they two completely different things or does multithreading use more than one core if it needs?

They are related but seperate.

Programs that support multithreading can use more than one core if more than one is available.

Most cores have two threads but when profiling my app I noticed lots of different threads ranging from thread 128 to thread 3460.

The operating system assigns threads numbers so it can keep track of them.

Most programs you will ever run will not need 3400 threads running at once. Also, a running thread will consume all of a core. The only reason your CPU isnt running at 100% all the time is that the operating system knows how to suspend the processor, which basically makes it stop everything and wait until something happens (such as an IO event or a clock tick). Only one thread can run on a core at once. Different threads running is actually just threads jumping onto the CPU and running for short periods of time, then being switched out with other threads which also need to run.

What dictates how many threads your computer has?

The total number of threads in all of your processes. Also, most operating systems impose a hard limit, a maximum number of existing threads that cannot be surpassed.

A process is a program (you probably know this). Multithreading is the process of having more than one thread per process (many processes will not make more than one thread because they do not have to). Windows does not have a hard limit on the number of threads you can create (at least, not since XP. Not going to say anything about w98 and previous), but of course the number of threads you can make is limited by how much memory you have.

You said some programs use multiple threads for reasons other than performance.

Sometimes it's nice to be able to multitask, even if not concurrently.

Sometimes programs need to do specific things at specific times. A commonly cited example is a program with a visible window. That program might be doing intense background number crunching, but it would benefit it if it could still respond to user events, like clicking buttons and resizing it. This can be accomplished with asynchronous processing, which will require your one thread to repeatedly check for GUI work to do at intervals, pause what it's doing, and handle the GUI for a while. Lots of things do it this way.

Another, possibly better way to handle it is with a thread. Your program doesn't have to worry about switching back and forth between number crunching and GUI management, the operating system will manage that for you. Even if you have only one core, you can still run multiple threads, and your OS will do its best to make sure that all of the running threads in all of the running processes get their fair share of CPU time.


The number of cores and number of threads are decoupled. You can have many threads running on a single core, and you can have situations where only one thread runs despite the presence of more cores (although I cannot think of a real life scenario where this would happen). Let's say multicore is a hardware characteristic, whereas the number of threads is something in the domain of the OS and the processes running on it.

Of course, with a single core you cannot have more than one thread running concurrently. The OS has to constantly switch back and forth between threads.


Most cores have two threads

Here, I think you are confusing the overloaded term "thread". As correctly pointed out by other answers, a thread usually refers to a "software" concept. But sometimes it is also used as a "hardware" concept. When a "core" has two "threads" (like in many new Intel chips), it means that the core can run two parallel threads, as if there were two cores. This is, however, usually called hyperthreading. See:

http://en.wikipedia.org/wiki/Hyper-threading

So if you have N threads (I mean software threads, those made within your application, or just by running different applications at the same time) and M processors (being cores, or the hardware threads explained above), the following happens:

  • N<=M: then the Operating System should assign each thread a differentprocessor. Then the application threads run truly in parallel.
  • N>M: then some threads have to share a processor.