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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:50:21+00:00 2026-05-27T13:50:21+00:00

I have some work that needs to be done in separate threads, the work

  • 0

I have some work that needs to be done in separate threads, the work is done on a std::vector<T> of objects.

I need to do the work and then in the main thread, wait on all the threads with a join().

I have done this the following way, but I think this isn’t a good idea, as I have only one pointer, and it points to something else each iteration of the loop.

struct properties 
{
    explicit properties(someobj obj) : obj_(obj) {}
    void operator()() { /*do something*/ } 
    someobj obj_;
};

boost::shared_ptr<boost::thread> t;
for (size_t tst = 0; tst <= myvector.size() - 1; ++tst) 
{ 
    properties props(myvector[tst]);
    t = boost::shared_ptr<boost::thread>(new boost::thread(props));

} 

//get main thread to wait till all t's are done, however is this a smart way to wait on multiple t's?? Which t is it going to wait on?
t->join();

Can anybody suggest a better way of doing this? Should I make a vector<boost::shared_ptr<boost::thread>> and loop through them and through my object vector?

  • 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-27T13:50:22+00:00Added an answer on May 27, 2026 at 1:50 pm

    You need to use a thread pool. Boost might provide one, though I don’t think it does. PPL and TBB provide them in their parallel_for_each functions.

    Loosely, the thread_group class provided by Boost should be what you need.

    Fundamentally, boost::thread is a wrapper on the OS thread, it’s not really a solid threading base. PPL and TBB provide parallel algorithms and data structures, which is much better to go.

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

Sidebar

Related Questions

I have a thread that does the following: 1) Do some work 2) Wait
I have an ASP.Net application that needs needs to have some work performed by
I have some AJAX work that brings across an additional form element that I
I have some CSS style that does not work in IE and that works
I have code examples from some of my previous work that help me to
I have finally started messing around with creating some apps that work with RESTful
I have a request for some contract work from an organization that uses Excel
I have a set of methods that do some utility work over SQL connection,
I have to work on some code that's using generic lists to store a
Suppose you have a subsystem that does some kind of work. It could be

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.