1

I am just finding my way around parallel programming in C# and understood the significance of cores and true parallel programming.

But I still have a question:

Say I have a long running task does that mean this will be executed using threads from thread pool and in different cores for true parallel programming.

Or does it depend on the actual delegate that is passed onto the task?

I Hope my question is clear.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
ckv
  • 9,567
  • 17
  • 85
  • 137
  • This [answer](http://stackoverflow.com/a/18882300/1082327) might help – PoweredByOrange Oct 02 '13 at 04:16
  • 2
    If you're asking if a *SINGLE* task will magically run concurrently across different CPUs: No. If you're asking about the .Net Task Parallel Library vs. .Net Thread pools: look at this link: [Should I use ThreadPools or Task Parallel Library for IO-bound operations?](http://stackoverflow.com/questions/5213695/should-i-use-threadpools-or-task-parallel-library-for-io-bound-operations) – paulsm4 Oct 02 '13 at 04:20

2 Answers2

2

The delegate itself makes no difference. It is the TaskScheduler that matters.

The default TaskScheduler will run them via the ThreadPool.. to have them run synchronously, you would pass in a TaskScheduler instance that is currently being used.. such as the static TaskScheduler.FromCurrentSynchronizationContext.

Simon Whitehead
  • 57,414
  • 7
  • 93
  • 127
1

True parallel programming requires multiple cores since threads must execute on separate threads to truly run in parallel.. In a single core system you can only achieve fake parallelism since different treads must share the core through allocated time slots. Other treads are waiting while the current thread is running on the single core.

TGH
  • 37,121
  • 10
  • 94
  • 126