0
votes

Lets say there's a machine with 8-cores CPU.

I'm creating 2 posix threads using standard pthread_create(...) function.

As I know there's no any garanties these threads always would be executed by a 2 different physical cores, but practically in 90% they will run simultaneously (or in parallel). At least for my cases I seen that top command shows 2 cpu's are running ... thus around 160-180% CPU usage

The question is:

What could be the scenario when 2 threads within a single process are running only on 1 physical core ?

1
That's easy. Never, (unless you consider hyperthreads as one core).Martin James
@MartinJames what are hyperthreads ?ampawd
@MartinJames hyperthreading ?ampawd
' hyperthreading ?' yes, or similar hardware optimizations of one CPU core that may allow one core to 'run two threads', kind-of.Martin James
@nos having the kernel dispatch the two threads to the same physical core at different times is not really what the OP asked, IME, (I may be wrong... :).Martin James

1 Answers

0
votes

Two cases:

1) The other physical cores are busy doing other stuff, so only one core gets used by this process. The two threads run in alternation on that core.

2) The physical core supports executing more than one thread concurrently using hyperthreading or something similar. The other physical cores are busy doing other stuff, so the best the scheduler can do is run both threads in a single physical core.