What exactly is the difference between a multi-threaded and a multi-core cpu in principle?


I’ve gone through various threads on this topic, yet there exists a question of mine left unanswered by the threads

From what I can understand, a single thread can perform multiple tasks “simultaneously”, in that it swaps between multiple tasks, dumping one, picking another, heading back to the first task picking up from where it’d left off and so on

Multiple threads, from what I assume, allows you to possess multiple threads swapping between multiple tasks

For instance, if I had a single core single threaded system, with two tasks to compute, the sole thread in the system would have to periodically switch between the first and the second task
Bumping it up to a single core dual threaded system, I could then delegate each thread to one of these tasks in question, allowing me to simultaneously compute and perform said tasks

Which brings me to multi-core systems. Wouldn’t a dual core single threaded system more or less end up delegating each of the single threaded cores to each of the tasks at hand? From what I hear, the sole differences would be in each core being in possession of **slightly** different system resources (I’d heard some multi-core chips share a portion of the cache)

I’m sure I am getting something wrong here. What really is the difference between, say, a single core dual threaded system and a dual core single threaded system? Both systems can allow for the simultaneous handling of 2 tasks right? If the two tasks happen to be spawned by the same process, I can see why they’d want to remain on the same core ( since they would want to access the same resources, thus necessitating the usage of a single core dual threaded system)

Is there anything else? Or have I gotten it wrong entirely?

In: 5

Ok so…. A lot of this is scrambled terminology.

So let’s go with the basics.

A thread is a bit of software whose execution can be delegated to different CPU cores.

A core is a part of the CPU that can process a thread independently from other cores. They do share some resources with other cores like cache memory, but for the most part execution of one core doesn’t affect execution on another core. So you can run multiple threads in parallel.

A hyperthreaded core cannot process multiple threads at the same time. However it can rapidly switch execution between two threads faster than a core can stop processing of one thread and start on another. It basically keeps the core from going idle as often.

One bit of terminology: you’re using the term “thread” as a feature of the cpu, but normally we use that word to describe the independent tasks that you want to run in parallel.

Open up Task Manager on your Windows PC, or Activity Monitor on your Mac, or type “ps aux” in your Linux terminal. That shows you all of the processes you have running right now. Each of those processes has at least one thread, maybe more. These days it’s common to have dozens or hundreds of threads at any one time. From your perspective as a user, all of those threads are running “simultaneously”.

Let’s say you have a single-core cpu without hyperthreading support. Your cpu can only do one thing at a time.

Your operating system is the one that makes this work. Every millisecond or so, it stops your cpu from working on one thread and starts it working on another one. It keeps going back and forth between all of the threads that have work to to.

If you have a dual-core cpu, that’s nearly identical to the idea of just having two cpus. Now your operating system can schedule two threads at the same time, but it’s still constantly interrupting each thread and swapping in another because you have way more threads than cores. Yes, it will prefer to schedule the same thread on the same cpu where possible for cache reasons, but it will work either way.

Now, some cpus have a feature called “hyperthreading”. This means the cpu can execute two threads at the same time. This generally only works when the two threads are doing different things.

But it works the same way. The operating system can take a single-core, hyperthreading system and schedule two threads to execute, then a millisecond later swap those out for two more threads and so on.

Or, you have have a dual-core machine with hyperthreading and then it can execute four threads at once.

>What really is the difference between, say, a single core dual threaded system and a dual core single threaded system?

It’s the difference between one cpu that tries to do two things at once, vs two separate cpus.

Hyperthreading is pretty darn good, but it works best when the two threads are doing different things. When you’re doing a task that’s very computationally challenging and very specific, like encoding a video, two cores will outperform one hyperthreaded core by a lot. But when you’re doing two unrelated tasks at the same time, one hyperthreaded core is nearly as fast as two cores.

Multi-threaded and multi-core are two sides of the same coin. Multi-threaded is a property of software that defines discrete lines of processing (threads) that generally do not depend upon each other. Multi-core is a property of a CPU that allows it to process multiple threads at once.

You could think of a thread as like its own separate application (process) that can be run simultaneously with another application (multi-tasking). Except that a single application can also be broken into multiple threads, so we use separate terminology for processes vs threads. For example it’s common for an application to at least have one thread for the GUI and one for the app logic, so the GUI doesn’t freeze up while it’s doing some heavy processing tasking. But the point of multiple threads is that they generally *don’t* need to access the same resources.

A core on the other hand is the main computation component of a CPU. CPUs have several different jobs: the manage the memory (RAM) usage, talk to other system hardware (I/O & buses), they have some temporary memory to store work in progress (cache), maybe they have built-in graphics processing (GPU), and they have a pipeline that parses the instructions received and distributes work to the core(s). But to run multiple threads at once they only need to duplicate the cores, which is the component where all the math and logic is processed, along with each core having some cache of its own.

As such there isn’t really anything called a “dual core single threaded system”. A system might have a dual core CPU (able to process 2 threads simultaneously), but pretty much all modern operating systems will support and use multiple threads themselves, as well as the applications that run under them.