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 3451124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:06:51+00:00 2026-05-18T09:06:51+00:00

In the boost::thread library, is there any mechanism to control how many threads (at

  • 0

In the boost::thread library, is there any mechanism to control how many threads (at most) are running at a time?

In my case, it would be most convenient to start N threads all at the same time (N may be hundreds or a few thousand):

std::vector<boost::thread*> vec;
for (int i = 0; i < N; ++i) {
   vec.push_back(new boost::thread(my_fct));
}
// all are running, now wait for them to finish:
for (int i = 0; i < N; ++i) {
  vec[i]->join();
  delete vec[i];
}

But I want Boost to transparently set a maximum of, say, 4 threads running at a time. (I’m sharing an 8-core machine, so I’m not supposed to run more than 4 at a time.)

Of course, I could take care of starting only 4 at a time myself, but the solution I’m asking about would be more transparent and most convenient.

  • 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-18T09:06:52+00:00Added an answer on May 18, 2026 at 9:06 am

    Don’t think Boost.Thread has this built in but you can overlay Boost.Threadpool (not an official library) onto Boost.Thread, and that does allow you to control the thread count via SizePolicy.

    The default is a fixed-size pool which is what you want – specify the initial (and ongoing) thread count on the threadpool constructor.

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

Sidebar

Related Questions

What are the differences in using boost:thread, Posix Thread library and the new C++11
I want to compile only the thread and regular expresession library of boost and
I am having some trouble using the pantheios logging library with boost::threads. It seems
A portable thread specific storage reference/identity mechanism, of which boost/thread/tss.hpp is an instance, needs
C++0x thread library or Boost.thread define non-member variadic template function that lock all lock
The boost threading library has an abstraction for thread specific (local) storage . I
It's not clear to me what linking options exist for the Boost.Thread 1.34.1 library.
C++0x thread library or Boost.thread define a non-member variadic template function that locks all
My Java library depends on Boost C++ . I've generated the following artifact: boost-maven-project:boost-thread:jar:windows-i386-vs10:1.47.0-b1
Is there some way to make boost::python control the Python GIL for every interaction

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.