Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I want to exit one thread from another thread. I pass thread_id to pthread_exit as pthread_exit((void *)MQthread_id); so it exit the current thread. can anybody guide me on this. ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50

    How to exit one thread from other thread

    Hi,

    I want to exit one thread from another thread. I pass thread_id to pthread_exit as

    pthread_exit((void *)MQthread_id);

    so it exit the current thread.

    can anybody guide me on this.

    Thanks

  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Posts
    25
    personally I prefer setting a variable to let a thread know it should terminate rather than terminating it externally, as this may cause side-effects. I don't know if the thread you wish to end just keeps going on and on in an endless loop, if it does, I suggest checking at the end of each loop if a variable telling it to shut down has been set.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50
    Thanks morfanaion.. It is a good solution.
    It is working fine now
    But Is it possible with pthread_exit() from other function in above situation.?

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    25
    I suppose it would be, but to be quite frank, I couldn't say. Since I've always preferred threads to maintain control over themselves, I've never tried it.

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Please, before posting questions, at least read the man page! :)

    But Is it possible with pthread_exit() from other function in above situation.?
    No.

    pthread_exit() does have one parameter, but that parameter serves a completely different purpose.

    To find out what it's for, read the man page:
    Code:
    man pthread_exit
    If that man page is not installed on your system, scroogle this:
    Code:
    Linux man pthread_exit
    Hope this helps.
    --
    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
  •  
...