How to check a detached thread. Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Lefteris
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Sep 16, 2008 8:32 am
Location: Thessaloniki, Greece

How to check a detached thread.

Post by Lefteris » Sun Mar 08, 2009 8:56 am

Hello all,

I have a detached thread running, and I have a button which stops it from running whenever I want it. The problem is that, it can stop by itself too if it finishes its task.

So stop button will be calling Delete() on a null object, which results on a crush. The problem is that checking with IsAlive() , or IsRunning results in a crush too, if the thread has finished. So the question is simple, what's the best way to see if a detached thread is still running, so as not to call Delete() on it if it has already terminated?

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Sun Mar 08, 2009 3:38 pm

Take a bool and set it to true as the last action in the thread.

Then, you can just check this bool.

Lefteris
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Sep 16, 2008 8:32 am
Location: Thessaloniki, Greece

Post by Lefteris » Sun Mar 08, 2009 5:01 pm

hm ... I thought of doing something like that, but it sounds like a really quick solution and not something permanent.

Surely there is a way to check if a detached thread is still running, isn't there? Or just because it is detached, there is just no way to see it?

neub
Knows some wx things
Knows some wx things
Posts: 28
Joined: Wed Sep 24, 2008 7:42 am

Post by neub » Wed Mar 25, 2009 11:34 am

There is no state-of-art solution for this problem:

I suggest that you read the post: http://forums.wxwidgets.org/viewtopic.php?t=23033 which treat different problem of how deleting Detached Thread.

Take also a look at my class wxNapThread my resume the discussion.

Post Reply