Thread Status.. How to know...???
Hi All,
Is it possible to know whether a thread is running or terminated by using the thread id in main function ( Thread id whose address has been passed as argument to the pthread_create function )... ? In C programming language..... If possible then how plz let me know.... Else how one can know the status of the spawned thread....? Thanking u all.... With Regard RajSun |
Yes, it is. The wait() function, or waitpid(), will cause the parent program to wait until the child process terminates (and thus, makes its status known).
It is best used within an if block, so that the waitpid() call is not accidentally called by the child process (which would be messy at worst, and uncompileable at best :)) Code:
#include <sys/types.h> G'luck! |
Thanks for replying my question.....
But Sir I m talking about THREADS such as Pthread library supported..... threads. |
Same thing, pretty much. Pthreads are more efficient but they're both ways to make unix fork off child processes, and they use the same message-passing algorithm - use a mutex to lock the memory location you use to store the message you'd like to pass.
i.e. Parent locks mutex Parent writes to buffer Parent unlocks mutex Child (which has been waiting on the mutex) locks mutex Child reads from buffer Child perhaps writes to buffer Child unlocks mutex etc etc etc. Take a look around google, there are many good resources for both forked processes and pthreads: http://www.llnl.gov/computing/tutorials/pthreads/ (The section on Condition Variables is probably the most helpful one here). I hope that helps a little more, I apologize for the misunderstanding! |
Thanks a lot man. I got a good material.....
|
All times are GMT -5. The time now is 07:08 PM. |