2

On my quad core cpu, it seems like a single thread (endless while loop) is being executed on 2 cores simultaneously. Why is this? Shouldn't a single thread be executed on one core only? enter image description here

1
  • Nevermind that an average process always has more than one thread, set the process affinity to limit the process to running all its threads on one core. Commented Oct 6, 2013 at 9:15

3 Answers 3

4
+50

A single tread can be run on as many cores as you have, but it will be limited to a single core at the same time.

Think of it as a phone conversation. You only have one single phone*1 and you need to keep talking into the phone*2. You have four people in the office, each capable of speaking*3 . Nothing prevents you from handing over the phone to another person while taking a toilet break.

Note that there is only one person speaking into the phone at the same time.


*1 The phone is the single tread.
*2 Need to keep talking as in it runs endlessly.
*3 The four people are ofc. the four cores.

8
  • How would the resources be managed? Is there a need to transfer L1 cache across the cores? Why doesn't it just execute on one core rather than 2 cores (is there a benefit...it seems like quite the contrary imo)?
    – agz
    Commented Oct 5, 2013 at 20:20
  • 1) Which resources? Could you expand that to be a bit more specific? 2) It is the scheduler in the OS decides on which core the process will run. Usually those try to keep the same process on the same core in order to benefit from cache hits and potential turbo boost features. 3) Cache coherency is handled by the CPU itself on the x86 architecture. You did not specify that you are using x86, but the picture of a task manager strongly hints at window and thus usually to x86.
    – Hennes
    Commented Oct 5, 2013 at 20:26
  • Did you take that taskmanager picture on a 2 physical, 4 logical core CPU?
    – Hennes
    Commented Oct 5, 2013 at 20:28
  • It is a core 2 quad q9650, 4 physical cores and 4 threads
    – agz
    Commented Oct 5, 2013 at 20:48
  • 2
    I do not have access to the windows task scheduler source or its logic. So I can not answer that for windows. The best I can do is guess. E.g. a driver which has a strong preference for core 0 which pushed the tread to another core. But I repeat: Guess
    – Hennes
    Commented Oct 5, 2013 at 21:01
0

In your screenshot I can see not two, but 4 threads using 4 cores in perfect harmony, with one couple of cores using their CPU more than the other couple, but the highs and lows of all the 4 cores are more or less synchronized to the same time segments.

This doesn't look at all like a single threaded process, but more like a 4-threaded process. This needs more examination.

The tool to use is Process Explorer. After you launch it, you can right-click the column-headers and select more columns if needed.

Once you locate the process that is using these CPUs, you can double-click it and choose the Threads tab to see how many threads it has and what they are doing (which system calls they use).

If the process is just svchost.exe, it is a system service, which can be identified. The one most likely to be using heavily the CPU is Windows Search.

0

That display in your posting is showing you how much activity is going on for each core but it tells you nothing about which processes/threads are running on which core.

I suspect that as your single threaded program gets it's "time slice" the OS is running it on one core half the time and another core the other half of the time. Maybe it even runs on the other cores some small part of the time too.

As an infinite loop it is using the core fully for the duration of it's time-slice, but any time increment of core activity (in the Task Manager) will represent MUCH MORE than the duration of single time slices.

For further insight as to what is going on, switch to the Processes tab on the Task Manager. On the View Menu, click Select Columns then tick the "Threads" column. Then on the Image name column find your process. Confirm that it is a single thread.

As I sit here with not that much "load" on my XP box there are 662 threads running. My Antivirus is running 78 threads, Firefox is running 45 threads, Dropbox is running 33. Winamp is not playing anything at all right now and it is still running 17 threads. Any increment in the Task Manager display could have had all of those threads on any core.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .