![Single threaded process being executed on 2 cores](https://linux22.com/image/1380364/Single%20threaded%20process%20being%20executed%20on%202%20cores.png)
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?
答案1
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.
答案2
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.
答案3
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.