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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:33:54+00:00 2026-05-25T15:33:54+00:00

Maybe there is a really simple solution for my problem, but I’m really confused

  • 0

Maybe there is a really simple solution for my problem, but I’m really confused with all the boosts around me.

Here’s my problem:

I want to start a task (calculation, file system operations, etc.), raised by a callback system which calls the CallbackReceived function and I want to pass this operation to a thread, typically represented by a member function of an object. The thread isn’t guaranteed to finish, so it should have something to cancel it after some time.

Something like (don’t know if this is 100% correct):

// ...
MyObject object;
// ...
void CallbackReceived(int parameter) {
  boost::thread tThread(&MyObject::calculate, *&object); 

  boost::asio::deadline_timer tDeadlineTimer(_ioService, boost::posix_time::seconds(2));
  tDeadlineTimer.async_wait(boost::bind(DeadlineTimeOut, boost::asio::placeholders::error));

  tThread.join();
}

Basically, a tThread.join()` waits for the return of the thread. While waiting, my main could not receive any callbacks that may come in because it’s blocked and sleeps.

So what can one do, to run the thread and not to block the calling initial program while executing the operation?

  • 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-25T15:33:55+00:00Added an answer on May 25, 2026 at 3:33 pm

    What do you want to do with the result of calculate?

    Your main thread is blocked in the .join().

    If you want to handle other callbacks, you have to return to the normal execution flow, waiting for another call.

    Then you have to ask yourself what do you do with the result of calculate when it’s finished. Maybe the thread can put the result in a shared resource somewhere and finish gracefully.

    You must first sort out all what your code is supposed to do ( processing callbacks, starting threads, what to do with the result ) then you can think of implementing it. There are new constructs in boost and C++11 called promise and future that could suit you but first you have to think about what you want.

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

Sidebar

Related Questions

Really annoying situation, and maybe there is an easier solution.. but I basically have
There maybe some simlar questions to this but I can't see anything that really
Maybe there is a proper term for this, but what if you want to
I'm not very good at regex but maybe there's a simple way to achieve
Maybe there is no difference, but is either way better than the other (or
Maybe there's no way to solve this the way I'd like it but I
I call this a flash meeting, but maybe there is another more appropriate name.
First of all, my question isn't really specific to C# or XNA, but my
This sounds really simple but it's like an onion - lots of layers as
Maybe there are VB.net and other language that related with .Net framework. When I

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.