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

  • Home
  • SEARCH
  • 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 6573207
In Process

The Archive Base Latest Questions

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

I noticed something strange. I expect a segfault to be produced running the following

  • 0

I noticed something strange. I expect a segfault to be produced running the following code, but it isn’t.

void DeadlineTimeOut(const boost::system::error_code& pErrorCode, boost::thread* pThread) 
{
    std::cout << "Error code: #" << pErrorCode.value() 
      << " Message: " << pErrorCode.message() << std::endl;
    std::cout << "Thread Address = " 
      << pThread << std::endl; // "sth. like 0x33aabc0"

    pThread->interrupt();
    pThread->join();

    delete pThread;
    delete pThread;

    std::cout << "Stopped execution thread #" 
      << pThread->get_id() << std::endl; // "{Not-any-thread}"
}

So, why is the double delete possible? And also calling a member? I’m a little confused at the moment.

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

    Deleting a pointer twice is undefined behaviour. There’s no guarantee of a segfault. You might get one if you’re lucky; you might not. The code might pass all your testing and then blow up in your customer’s face at the worst possible moment. See the C++ FAQ.

    The same goes for dereferencing a pointer that’s been deleted (the pThread->get_id() in your code).

    A simple defensive technique is to set pointers to NULL as soon as they’ve been deleted, instead of letting them dangle. This may help catch some bugs of this type.

    The above applies to pointers of any type, and not just boost::thread*.

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

Sidebar

Related Questions

I was playing around with some code when I noticed something strange: [~] main%
I just noticed something strange. If I have this XML: <level number=7 background=background_5> and
Let me start from a real life example: Customer: Alex, just noticed something strange
Possible Duplicate: Puzzling Enumerable.Cast InvalidCastException Hi, I just noticed something quite strange with the
Okay, I've noticed something, but couldn't find it in the CSS spec. Styling an
i have just noticed something strange in some asp.net markup. I have a standard
I noticed something strange while executing a select from 2 tables: SELECT * FROM
I'm debugging a program I wrote and noticed something strange. I set up an
I was working on an android project, and while designing i noticed something strange
This question arose out of something strange that I noticed after investigating this question

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.