26

can a single process run different threads on different cores?

(I think they can)

In that case, different cores share the same address space but with different caches? Does that mean caches will be redundant?

Thanks!

  • 1
    A single process can contain multiple threads, yes. – Phoenix Aug 03 '16 at 03:01
  • Can they be scheduled to run on any core? When a process gets loaded on a CPU, I understand the registers' contents are switched; how does that work with multiple CPUs? –  Aug 03 '16 at 03:25
  • 3
    Check http://programmers.stackexchange.com/questions/181157/how-to-program-thread-allocation-on-multicore-processors – Rupsingh Aug 03 '16 at 05:57

2 Answers2

22

Yes, a single process can run multiple threads on different cores.

Caching is specific to the hardware. Many modern Intel processors have three layers of caching, where the last level cache is shared across cores.

It does not mean the non-shared caches are redundant, but it does have implications for multicore performance. In particular, if one core updates a value in the address space that currently lives in another core's private cache, then a cache coherence protocol must be run to ensure that another core can no longer read a stale value.

merlin2011
  • 71,677
  • 44
  • 195
  • 329
14

A single process can run threads simultaneously on multiple processors IF the underlying system schedules threads (and not processes) for execution (aka kernel threads). This is the way threads are implemented on most systems these days (e.g., Windows, Linux).

However, there are still some systems that schedule processes for execution. On such systems, threads are scheduled by a library (aka user threads). In other words, the process schedules its own threads for execution. On those systems, the threads for the process executing on the same processor.

Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
user3344003
  • 20,574
  • 3
  • 26
  • 62
  • How can you find if your system uses kernel, user or both type of threads? – Themelis Mar 13 '19 at 21:39
  • 1
    You have to check the system documentation. [Almost] All systems support simulated "user" threads because they are libraries and not part of the kernel. – user3344003 Mar 14 '19 at 00:33