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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:07:30+00:00 2026-06-12T23:07:30+00:00

In my c++ class I make a thread and give the pointer this to

  • 0

In my c++ class I make a thread and give the pointer this to the thread. Now somewhere this object is getting deleted. I want the thread to exit after object is deleted.

One method is to use try-catch. Whenever I find an exception I exit the thread. But thats kind of a hack.

  • 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-12T23:07:31+00:00Added an answer on June 12, 2026 at 11:07 pm

    Now somewhere this object is getting deleted. I want the thread to
    exit after object is deleted.

    This is completely backwards. What you want to do is to signal the thread to exit somehow and have the thread clean up the object itself. In other words, there has to be some kind of cooperation between the “master” thread and the “worker” thread(s).

    This is because the thread itself might want to be able to do something with the object before exiting, and if you delete it then cause the thread to exit, your program will almost certainly die from access violation exceptions.

    Consider using boost::thread, which has built-in support for cooperative thread cancellation. The thread will periodically check when it’s time to exit using one of the interruption points, performing any necessary cleanup. That way, the “master” thread doesn’t have to deal with deleting the object itself, it can just signal the thread to exit, and it’ll take care of itself (assuming you implement this correctly).

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

Sidebar

Related Questions

i make one class file for jar. and this class have use wurfl. and
I want to make a thread in red5 application? this thread will send data
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
I have this CSS. the property FILTER In class .crumb make my background and
In my project every class object has its own thread with infinite cycle (while(1))
I want to make server application. In the beginning it should make thread for
I am trying to make my_class thread-safe like so. class my_class { const std::vector<double>&
Why the these methods java.lang.Thread.currentThread(), java.lang.Thread.sleep(), java.lang.Object.notify(), java.lang.Object.wait() of Thread & Object class are
Why does defining __getitem__ on a class make it iterable? For instance if I
So I've been given an assignment in my Mobile apps class: make a color

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.