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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:34:25+00:00 2026-06-11T00:34:25+00:00

I´m trying to write a function that handles both input arguments and return values

  • 0

I´m trying to write a function that handles both input arguments and return values from a thread in a thread group.

My example class:

  // includes...
class MyClass(int id)
  {
  thread_id = id;
  i = id* 5; 
  b = false;
 }

void resetCounter(int j){
  i = j * 5;
 }
int getId(){
 return id;
}
bool getBool(){
  return b;
 }

void DoWork(){
  while( i > 0 ){
     boost::this_thread::sleep(boost::posix_time::seconds(i));
      i--;
  }
  b = true;  // DoWork will in the real code be able to return false!
  }
  private:
  bool b;
  int i;
  int thread_id
 };

  boost::threadgroup threads;

Exemple code:

  bool exist = false;
  for(int i=0;i<4;i++){
  // first check if thread id exist (possible)? 
  // If so don´t create a new thread but reset the counter!
  if(exist){
   // in current thread call reset "i" (w.resetCounter(i))
   }else{
    MyClass m(i);
    boost::function<void()> thread_func = boost::bind(&MyClass::DoWork, &m);
    threads.create_thread(thread_func);
   }
 }

I want to iterate through the threads and be able to check if DoWork returned true.

How do I implement this?

  • 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-06-11T00:34:26+00:00Added an answer on June 11, 2026 at 12:34 am

    First of all, with thread_group you can’t iterate over the thread objects. So if this’s what you want, consider storing thread objects in some other container.

    Besides, you can’t portably wait until one thread finishes, but if you don’t mind using Windows-specific API, you can do this with WaitForMultipleObjects.

    However, I would recommend you re-designing your application, to avoid such tricks.

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

Sidebar

Related Questions

i am trying to write a function that will make DataRow[column] return nullable typed
I am trying to write a function that can handle both char & wchar_t
I am trying write a function that generates simulated data but if the simulated
I am trying to write a function that will allow me to browse for
I am trying to write a function that can take three parameters: an SqlDataReader,
I'm trying to write a function that will: If there is no region selected,
I am trying to write a function that takes two containers of the same
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that includes a file named header.php in
I am trying to write a function that will filter a list of tuples

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.