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 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

Boost is a very large library with many inter-dependencies -- which also takes a
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
Is there some way to make boost::python control the Python GIL for every interaction
I wanted to use boost::thread in my program, but get the following compiler error
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
Boost is meant to be the standard non-standard C++ library that every C++ user
When the Boost library/headers is used with VC++ 9 compilers (Visual C++ 2008 Express
I use the Boost Test framework for my C++ code but there are two
I have a Boost unit test case which causes the object under test to

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.