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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:28:55+00:00 2026-05-25T16:28:55+00:00

my question is about a running deadline timers which wait for some operations represented

  • 0

my question is about a running deadline timers which wait for some operations represented by the same function to finish: But i dont’t know, where to free my thread and deadline object after a safe finish oder an interrupt by deadline time out. When can that happen?

boost::asio::deadline_timer* mDeadline1;
boost::asio::deadline_timer* mDeadline2;
boost::thread* mThread1;
boost::thread* mThread2;

// start deadline timers
mDeadline1 = new boost::asio::deadline_timer(_io_service, boost::posix_time::seconds(2));
mDeadline1->async_wait(&MyClass::DeadlineTimedOut, this);

mDeadline2 = new boost::asio::deadline_timer(_io_service, boost::posix_time::seconds(2));
mDeadline2->async_wait(&MyClass::DeadlineTimedOut, this);


// Run operations in threads
mThread1 = new boost::thread(&MyClass::DoSomething, this);
mThread2 = new boost::thread(&MyClass::DoSomething, this);
// ...

void MyClass::DoSomething() {
  // Do something time expensive and sleep, etc. for interrupt point ...

  // which to cancel here!?
  mDeadline->cancel();
  delete mDeadline;
}

void MyClass::DeadlineTimedOut(const boost::system::error_code& pErrorCode) {
  if(pErrorCode == 0) { // deadline timed out

    // which to interrupt here?
    mThread->interrupt();
  }

  if(pErrorCode == 995) { // deadline cancelled from outside

  }
}

Has anyone some advice? Graceful, B.

  • 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-25T16:28:56+00:00Added an answer on May 25, 2026 at 4:28 pm

    The timers as they stand are meaningless – only you know what they mean and what they are supposed to do – so you have to decide what to cancel. As to cleaning up, hold them in a scoped_ptr or shared_ptr and they will be automagically cleaned up when the scope/last reference is done.

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

Sidebar

Related Questions

I have a question about how PHP handles filesystem operations. I'm running this code
I have a question about why some SQL (running on SQL Server 2005) is
I've asked a different question about directory watching, which was answered, but the other
This is a question about some stored procedures running on MSSQL 8 (I think
Currently I'm running some code and got some question about this. Below are the
I got a quick question about running a directX application (C++) in a managed
I have a question about debugging a running C++ program in Linux. If a
I asked a question a couple days ago about creating INSERTs by running a
This question about Timers for windows services got me thinking: Say I have (and
I am running into a question about equals and hashCode contracts: here it is

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.