Hypothetically, if you (I / someone) were to create a multi-threaded application, utilising the processing powers of multiple cores (for example, using TPL in C#). Would that program crash, if it were run on a computer with a single core? Or rather, would the application move to context switching / time-slicing?
-
Have added an example, hopefully it's clearerGeorge Grainger– George Grainger2016年12月09日 10:17:31 +00:00Commented Dec 9, 2016 at 10:17
-
2Multi threading/tasking is much older than multi-core consumer CPUs. Threads get assigned short time slices, no matter how many cores your CPU has.CodesInChaos– CodesInChaos2016年12月09日 10:22:11 +00:00Commented Dec 9, 2016 at 10:22
-
Okay, so can you explain what would happen in the case above?George Grainger– George Grainger2016年12月09日 10:22:52 +00:00Commented Dec 9, 2016 at 10:22
-
2You can set the cpu core affinity mask for a process in the task manager to simulate a single core CPU.CodesInChaos– CodesInChaos2016年12月09日 10:23:09 +00:00Commented Dec 9, 2016 at 10:23
-
In your example of the TPL, it just won't do anything in parallel. That library adjusts to the cores available and spawns an appropriate number of threads for the available cores. So no it won't crash and no it won't use context switching. Other multi-threaded solutions will behave differently.David Arno– David Arno2016年12月09日 10:28:03 +00:00Commented Dec 9, 2016 at 10:28
1 Answer 1
No, multi-threading is much older then multi-core cpus. Even with multi-core cpus we use today, the number of threads on our systems vastly outnumbers the amount of cores. The specifics on how cpu time is allocated to each thread is OS dependent.
-
1Some multithreaded programs can actually be more efficient on a single core as wellNick Zuber– Nick Zuber2016年12月09日 16:03:25 +00:00Commented Dec 9, 2016 at 16:03