Results 1 to 4 of 4
Hi,
I'm new to Linux (and threads), and should check if a certain thead has finished, how can I do this?
It seems like it should be quite simple but ...
- 08-26-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
how can i get the status of a thread (mainly check if it's done)?
Hi,
I'm new to Linux (and threads), and should check if a certain thead has finished, how can I do this?
It seems like it should be quite simple but i've been googling this for hours with no results...
Thanks a lot,
Neta.
- 08-26-2008 #2The closest available mechanism is pthread_join(), but that doesn't really work too well.check if a certain thead has finished, how can I do this?
Your only real choice is to do the bookkeeping yourself. Before firing up a thread, the parent thread should allocate some bookkeeping memory for that thread and initialize it. The object thread should then modify that memory appropriately before exiting.--
Bill
Old age and treachery will overcome youth and skill.
- 08-31-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
Thanks, but I'm not sure i'll be able to do the bookkeeping (I'm trying to port some code to linux and want to keep it as close to the original)...
Do you know what happens if one tries to call to pthread_cancel with thread that was already terminated? is the ESRCH value returned?
thanks again,
Neta.
- 08-31-2008 #4That's what Butenhof says, and I believe him.Do you know what happens if one tries to call to pthread_cancel with thread that was already terminated? is the ESRCH value returned?
And it looks like a safe way to take care of this, as long as there is no call anywhere in the object thread's code to pthread_setcanceltype(). If there is such a call, then there's a whole new series of questions to ask yourself, which can have dangerous answers.
Also: if your call to pthread_cancel() is just to test the existence of a thread, rather than to cancel it, I strongly recommend that you put a conspicuous comment in the code saying this. Otherwise, the next person coming along will be baffled and could spend days trying to untangle what's going on.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote