Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    check if a certain thead has finished, how can I do this?
    The closest available mechanism is pthread_join(), but that doesn't really work too well.

    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.

  3. #3
    Just 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.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Do you know what happens if one tries to call to pthread_cancel with thread that was already terminated? is the ESRCH value returned?
    That's what Butenhof says, and I believe him.

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...