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

  • Home
  • SEARCH
  • 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 6911173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:55:04+00:00 2026-05-27T08:55:04+00:00

I expect there are many possible solutions to this question, I can come up

  • 0

I expect there are many possible solutions to this question, I can come up a few myself, some clearly better than others but none that I am certain are optimal so I’m interested in hearing from you real multi threading gurus out there.

I have circa 100 pieces of work that can be executed concurrently as there are no dependencies between them. If I execute these sequentially my total execution time is approx 1:30s. If I queue each piece of work in the thread pool it takes approx 2m, which suggests to me that I am trying to do too much at once and context switching between all these threads is negating the advantage of having those threads.

So based on the assumption (please feel free to shoot me down if this is wrong) that if I only queue up to the number of cores in my system (8 on this machine) pieces of work at any one time I will reduce context switching and thus improve overall efficiency (other process threads not withstanding of course), can anyone suggest the optimal pattern/technique for doing this?

BTW I am using smartthreadpool.codeplex.com, but I don’t have to.

  • 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-05-27T08:55:05+00:00Added an answer on May 27, 2026 at 8:55 am

    A good threadpool already tries to have one active thread per available core. This isn’t a matter of having one thread for work per core though, as if a thread is blocking (most classically on I/O) you want another thread using that core.

    Trying the .NET threadpool instead might be worth a try, or the Parallel class.

    If your CPU is hyper-threaded (8 virtual cores on 4 physical) this could be an issue. On average hypter-threading makes things faster, but there are plenty of cases where it makes them worse. Try setting affinity to every other core and see if it gives you an improvement – if it does, then this is likely a case where hyper-threading is bad.

    Do you have to gather results together again, or share any resources between the different tasks? The cost of doing this could well be greater than the savings of multi-threading. Perhaps they are so unnecessarily though – e.g. if you are locking on shared data but that data is only ever read, you don’t actually need to read with most data-structures (most but not all are safe for concurrent reads if there are no writes).

    The partitioning of the work could be an issue too. Say the single-threaded approach works its way through an area of memory, but the multi-threaded approach gives each thread its next bit of memory to work with round-robin. Here there’d be more cache-flushing per core as the “good next bit” is actually being used by another core. In this situation, splitting work into bigger chunks can fix it.

    There are plenty of other factors that can make a multi-threaded approach perform worse than a single-threaded, but those are a few I can think of immediately.

    Edit: If you are writing to a shared store, it could be worth trying a run where you just throw away any results. That could narrow down whether that’s where the issue lies.

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

Sidebar

Related Questions

This is a theoretical question, so expect that many details here are not computable
I hope there's a SharePoint expert here on SO who can help with this.
There are many questions on this site about return value optimization (I suppose it's
This is a general question, and I don't expect any specific solution here. I'm
I am posting this in the off chance there is a SCORM expert out
My expect code does this: It does a ssh connect to another machine, sends
I don't expect a straightforward silver bullet answer to this, but what are the
How long can I expect a client/server TCP connection to last in the wild?
This question is related to my question on existing coroutine implementations in Java .
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Edit: This has nothing

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.