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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:51:54+00:00 2026-05-27T21:51:54+00:00

I just tested something like this: boost::thread workerThread1(boost::bind(&Class::Function, this, …); boost::thread workerThread2(boost::bind(&Class::Function, this, …);

  • 0

I just tested something like this:

boost::thread workerThread1(boost::bind(&Class::Function, this, ...);
boost::thread workerThread2(boost::bind(&Class::Function, this, ...);

and it works fine. What i now want, is to create as many Threads as i have objects in a list. I have experimentet with boost::foreach and this works fine. But i have problems with the names of the threads.

So simplified the code looks like this:

for
{
    boost:thread name(...);
}

but of course name cant be right here in the loop because it overwrites itself and isnt accessible after the loop. How do i create the threads so that i can join them all after all have been created?

  • 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-27T21:51:54+00:00Added an answer on May 27, 2026 at 9:51 pm

    Can you not just create a list (or similar) of threads and then just create them and add to the list.

    Something like the following (which is likely more pseudo code that anything 🙂 )

    list<boost::thread*> threads;
    
    for
    {
        boost::thread* name = new boost::thread(...);
        threads.push_back(name);
    }
    

    As mentioned in another answer you can use smart pointers which would be better and you mentioned you have a defined number of threads so an array/vector would be a better choice but as I said the code above isn’t perfect anyway

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

Sidebar

Related Questions

Really simple question: Am I missing something? Seems like this should be all that
I just tested which type of code is executed by the WinForms Designer in
I just tested Geolocation on Firefox 3.6 and iPhone Safari (os 3.1.3), the result
My MySQL database can store the euro symbol just fine (as I have tested
I just installed cucumber, and I tested it. I got the following error: teefcomp:cucumber-intro
I am just wondering if I'm doign something that might be bad, although it
You'd think that it would be simple, isn't there something simple to do this?
So I have a helper method that looks something like the following: private D
I'd like to write an extension method for the .NET String class. I'd like
Converting my current code project to TDD, I've noticed something. class Foo { public

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.