0
votes

I am a beginner in multi threading. So much new concepts so far. Can someone make a little explanation between core and CPU? I tried googling and it didn't help much.

Bottom line, is single thread run on single core or single CPU?

Also, I have i7. It says I have 4 cores, but 8 threads. Isn't core related with thread in 1-1 proportion? How did it double it?

Thanks in advance!

3

3 Answers

3
votes

A CPU, in this context, is a single physical chip which can be installed separately from other CPUs on the computer (should there be a place for multiple CPUs).

A "core" is a processing element of a CPU that is a distinct piece of hardware from other cores. If a CPU provides more than one core, the expectation is that the cores not only execute independently of each other, but that they do not contend for most resources on the same CPU to do their execution. That is, multiple cores provided by the same CPU are not sharing much of the CPU's hardware.

A "thread" in this context(note: the term "thread" as used in most programming contexts is related but different) is a path of code execution, with its own distinct set of registers. A core provides one or more threads. However, if a CPU core exposes multiple threads (typically only 2), the expectation is that the threads do contend with each other for execution resources.

The idea with multi-threaded cores (commonly called hyperthreading) is that cores have lots of execution resources. And a single stream of instructions cannot always saturate all of these resources. So if a core runs instructions from two threads, it can more efficiently use its computational resources.

And sometimes operations just shut a thread down. Memory fetches often can stop a thread in its tracks to wait for the data from RAM. At those times, a second thread on the core will get the core to itself until the data arrives.

1
votes

When Intel’s CPU designers started developing cores that could emulate 2 cores (a trick that sometimes makes better use of the limited cache capacity than a single core could), they decided to appropriate the word “thread” to describe them. They might just as well have chosen “virtual core” instead, but didn’t. They then stuck the word “hyper” in front to, well, I don’t know why. The term Hyperthread is just annoying for the confusion it causes with OS threads, which is a different thing altogether.

Other processors have done this before. The Inmos Transputer could emulate numerous cores, but were commonly thought of as “processes”, though the motivation there had nothing to do with efficient exploitation of a cache (it was intended to support the language we used on them, Occam, which was an implementation of Communicating Sequential Processes, something that is suddenly fashionable again in languages like Go, Rust).

1
votes

It is a common misunderstanding. There are two kind of threads , Software and hardware. While writing multi-threaded programs, You are talking about software threads. While talking about 4 (physical) cores with 8 (logical) HT(Hyper-threaded) cores, you are talking about hardware threads. The number of active software threads could be in 1000's, scheduled in a time-sliced manner by operating system (OS), on limited number of hardware threads.