Threads vs Cores

25,056

Solution 1

That's basically correct, with the obvious qualifier that most operating systems let you execute far more tasks simultaneously than there are cores or threads, which they accomplish by interleaving the executing of instructions.

A system with hyperthreading generally has twice as many hardware threads as physical cores.

Solution 2

A thread differs from a process. A process can have many threads. A thread is a sequence of commands that have a certain order. A logical core can execute on sequence of commands. The operating system distributes all the threads to all the logical cores available, and if there are more threads than cores, threads are processed in a fast cue, and the core switches from one to another very fast.

It will look like all the threads run simultaneously, when actually the OS distributes CPU time among them.

Having multiple cores gives the advantage that less concurrent threads will be placed on one single core, less switching between threads = greater speed.

Hyper-threading creates 2 logical cores on 1 physical core, and makes switching between threads much faster.

Solution 3

The term thread is generally used as a description of an operating system concept that has the potential to execute independently of other threads. Whether it does so depends on whether it is stuck waiting for some event (disk or screen I/O, message queue), or if there are enough physical CPUs (hyperthreaded or not) to allow it run in the face of other non-waiting threads.

Hyperthreading is a CPU vendor term that means a single core, that can multiplex its attention between two computations. The easy way to think about a hyperthreaded core is as if you had two real CPUs, both slightly slower than what the manufacture says the core can actually do.

Solution 4

Basically this is up to the OS. A thread is a high-level construct holding a instruction pointer, and where the OS places a threads execution on a suitable logical processor. So with 4 cores you can basically execute 4 instructions in parallell. Where as a thread simply contains information about what instructions to execute and the instructions placement in memory.

An application normally uses a single process during execution and the OS switches between processes to give all processes "equal" process time. When an application deploys multiple threads the processes allocates more than one slot for execution but shares memory between threads.

Normally you make a difference between concurrent and parallell execution. Where parallell execution is when you actually physically execute instructions of more than one logical processor and concurrent execution is the the frequent switching of a single logical processor giving the apperence of parallell execution.

Share:
25,056
teonghan
Author by

teonghan

Updated on July 09, 2022

Comments

  • teonghan
    teonghan almost 2 years

    Say if I have a processor like this which says # cores = 4, # threads = 4 and without Hyper-threading support.

    Does that mean I can run 4 simultaneous program/process (since a core is capable of running only one thread)? Or does that mean I can run 4 x 4 = 16 program/process simultaneously?

    From my digging, if no Hyper-threading, there will be only 1 thread (process) per core. Correct me if I am wrong.

  • user3731622
    user3731622 over 7 years
    You might want to be careful with the use of "simultaneously." To a user it might appear some tasks are happening simultaneously, but the actual hardware might not be performing the each task simultaneously. I think @mikaelbrandin post with info on parallel vs. concurrent is useful.
  • Alex S
    Alex S over 7 years
    @user3731622 I made that exact point in my answer by explaining that CPUs can interleave instructions. How could I make it any clearer?
  • user3731622
    user3731622 over 7 years
    Your answer is probably quite clear to experienced people. One way you could make it a little more clear for inexperienced people is if you use some form of the word appear along with simultaneous or parallel and describe how something might appear simultaneous when it isn't actually simultaneous.
  • Jirka Hanika
    Jirka Hanika about 4 years
    This does answer the question as asked, but if it comes up in a search by somebody trying to understand hyperthreading (as a terminological difference between cores and threads - see the question subject line), they'll have hard time understanding which statement you claim is correct and why; you then explain your answer only very indirectly by implying that 4 would hardly be the ratio of threads to cores.
  • Peter Cordes
    Peter Cordes over 3 years
    Hyper-Threading doesn't make thread-switching faster; it lets 2 threads truly be running simultaneously on the same physical core. (Alternating cycles in the front-end, with out-of-order scheduling to competitively share the execution units in the back-end). Can a hyper-threaded processor core execute two threads at the exact same time? / lighterra.com/papers/modernmicroprocessors. Also note that hardware theads is standard terminology for number of logical cores (execution contexts), but yes it's very different from SW threads.