I have a couple of small questions.
Firstly is there a difference between multithreading and multicore? Are they two completely different things or does multithreading use more than one core if it needs?
Secondly Most cores have two threads but when profiling my app I noticed lots of different threads ranging from thread 128 to thread 3460. What dictates how many threads your computer has?
Thanks
Multiprocessor – multiple CPUs tightly coupled enough to cooperate on a single problem. Multithreaded processors (e.g., simultaneous multithreading) – single CPU core that can execute multiple threads simultaneously. Multicore processors – multiprocessor where the CPU cores coexist on a single processor chip.
In computer architecture, multithreading is the ability of a central processing unit (CPU) (or a single core in a multi-core processor) to provide multiple threads of execution concurrently, supported by the operating system. This approach differs from multiprocessing.
Cores is an actual hardware component whereas thread is a virtual component that manages the tasks. Cores use content switching while threads use multiple CPUs for operating numerous processes. Cores require only a signal process unit whereas threads require multiple processing units.
A multicore system has a single processor with multiple execution units called cores while a multiprocessor system has two or more processors. Multiprocessors are more reliable compared to multicore processors but the multicore processor has less traffic compared to multiprocessors.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With