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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:17:29+00:00 2026-06-17T00:17:29+00:00

I have a C++ application in which I use Boost Threads to provide concurrency.

  • 0

I have a C++ application in which I use Boost Threads to provide concurrency. The basic sample is as follows:

processingThreadGroup->create_thread(boost::bind(process, clientSideSocket, this));

Here, processingThreadGroup is a shared pointer to a thread pool in boost, and process is the function that I need to call. The clientSideSocket and this are parameters that should be passed to the process function.

Inside the process function, I throw a custom Exception if an error is detected. The process function sends data to a remote server. So my question is, how to I propagate this error up the call stack? I want to shut down the system after a clean up. Tried the following:

try {
    processingThreadGroup->create_thread(boost::bind(process, clientSideSocket, this));
} catch (CustomException& exception) {
    //code to handle the error
}

But didn’t work. Any idea on how to do this properly?

Thanks!

  • 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-17T00:17:31+00:00Added an answer on June 17, 2026 at 12:17 am

    To propagate return values and exceptions you should use futures. Here is a simple way to do it:

    // R is the return type of process, may be void if you don't care about it
    boost::packaged_task< R > task( boost::bind(process, clientSideSocket, this) );
    boost::unique_future< R > future( task.get_future() );
    
    processingThreadGroup->create_thread(task);
    
    future.get();
    

    This has a number of gotchas that you have to keep in mind. First, the lifetime of task has to extend the asynchronous execution of process. Second, get() will block until the task is finished and return its value if it ended successfully, or propagate the exception if one was thrown. You can use all kind of functions to check the state of the future, like has_value(), has_exception(), is_ready().

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

Sidebar

Related Questions

I have an application which runs multiple threads. I use MadExcept to catch errors
I have application which needs to use a dll (also written by me) which
I have an Access application which use SQLServer 2008 R2 as database. When I
I have an application which will use WCF to serve up various chunks of
I have an application in which we use a hand-made build system.The reason for
I have a socket application which I can use in local network, at home.
I have a simple C# Console application in which I use FileSystemWatcher and Moving
I have a MFC dialog based application in which I use ::system() function to
i have an windows mobile application written in c# compact framework which use barcode
I have C# application that makes use of some C libaries(which I have written

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.