Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:12:38+00:00 2026-06-10T11:12:38+00:00

This question ideally solicits the opinion of advanced users. I’m optimizing some number crunching

  • 0

This question ideally solicits the opinion of advanced users.

I’m optimizing some number crunching code and have a few processor cores free. In order to make use of them effectively, I am looking at some fine-grained concurrency using tasks (Task.StartNew) for extremely short-running operations (100 to 500 milliseconds). There is no UI involved here at all.

One crucial element here is use of the ThreadPool which allows performance benefit for short-running tasks without the overhead of thread creation. There are some scenarios, however, where it is more natural to think in loops rather than tasks (e.g. Parallel.For).

I understand that Tasks use the ThreadPool but am not sure about Parallel.For. The question is:

  • Which constructs make use of the ThreadPool?
  • Can Parallel.For be configured to use the ThreadPool or does it always incur thread creation overhead?
  • Not part of the main question but any links to maximizing parallelism would help.

Please note that this question is specific to .NET 4. Upgrading to 4.5 is not an option at the moment.

UPDATE:
Based on Daniel Kinsman’s comment, consider the following:

System.Threading.Tasks.Parallel.For(0, 100, i => { System.Console.WriteLine("Is ThreadPool @ low priority: " + System.Threading.Thread.CurrentThread.IsThreadPoolThread); });
System.Diagnostics.Process.GetCurrentProcess().PriorityBoostEnabled = true;
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;
System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
System.Threading.Tasks.Parallel.For(0, 100, i => { System.Console.WriteLine("Is ThreadPool @ high priority: " + System.Threading.Thread.CurrentThread.IsThreadPoolThread); });

If you have a multi-core machine, IsThreadPoolThread will return non-deterministic results depending on how many applications you have running.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:12:40+00:00Added an answer on June 10, 2026 at 11:12 am

    Parallel.For, by default, ‘always’ uses threadpool to run tasks and does not incur thread creation overhead.

    As of current release of .Net 4.0 CLR, Parallel.For internally uses ThreadPoolTaskScheduler class (an internal class) to run its tasks. Off-course this is internal detail subject to change but in all probability Parallel.For will continue to use ThreadPool to run its tasks. If you don’t want to take this ‘risk’ then you can always write your own TaskScheduler and provide it to Parallel.For using ParallelOptions Class

    If you have a multi-core machine, IsThreadPoolThread will return
    non-deterministic results depending on how many applications you have
    running.

    Explanation:

    ThreadPoolTaskScheduler class is an optimized task scheduler that tries not to run a task on a thread if not necessary, i.e. if the task can be executed straight away, it does so on the current thread which might not be a ThreadPool thread. The ‘false’ output you see is for this case. But if it can not imeediately run the task, it always uses thread pool to queue the task for later execution.

    Note that in both the cases there is no thread creation ‘overhead’ (not entirely true as ThreadPool might itself decide to include new threads in the pool on some heuristic)

    You can use the following code to confirm this:

    Thread.CurrentThread.Name = "MyThread";
    System.Threading.Tasks.Parallel.For(0, 100, i => Console.WriteLine(i + ". Is ThreadPool: " + Thread.CurrentThread.IsThreadPoolThread + " Name: " + Thread.CurrentThread.Name));
    

    You will be able to notice that for all the ‘false’ cases thread name is ‘MyThread’.

    Regarding maximizing parallelism, CPU bound work can be parallelised only to the extent of number of CPU cores available. TPL takes this into account and is well suited and optimized for parallel computing of CPU bound tasks. By using TPL you are on right path and should continue on this path 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question comes from a need to ensure that changes I've made to code
This is an exact duplicate of this question ; however the code linked in
G'day, OK, I have now rewritten this question totally: I am trying to import
I feel like this question ought to have been covered, but I can't seem
(Briefly, like this question but for Windows servers.) I have several Win2003 servers running
Ok, this question is best explained in code. So will try to present the
I'm not understanding some key bit of ExtJs idiom so this question is about
Before asking this question I have Googled for this problem and I have looked
Variants of this question have been asked several times now here, but my question
I know I have asked this question in a different manner earlier today but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.