By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,486 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,486 IT Pros & Developers. It's quick & easy.

invalid threads ID

P: n/a
Hello, Im implementing an multithread application under linux with
gcc and kdevelop. I use pthread library from linux to handle threads
and mutex. My question is how can my program detect if a thread struct
is still valid or active.... I use a library that call a function
pthread_kill (threadID,0) in order to detect if a thread is alive but
when the thread Id is invalid, it causes a segmentation fault.
Ex:
if (threadID==0)
return FALSE;

if (pthread_kill(threadID,0)!=0)
{
......
return TRUE;
}
else
{
.......
return FALSE;
}
Thanks

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
martini wrote:
Hello, Im implementing an multithread application under linux with
gcc and kdevelop. I use pthread library from linux to handle threads
and mutex. My question is how can my program detect if a thread struct
is still valid or active.... I use a library that call a function
pthread_kill (threadID,0) in order to detect if a thread is alive but
when the thread Id is invalid, it causes a segmentation fault.


Since C++ has no means for multithreaded programming, your best bet is
to ask in either the newsgroup for your OS or in comp.programming.threads.

V
Jul 23 '05 #2

P: n/a
Ian
martini wrote:
Hello, Im implementing an multithread application under linux with
gcc and kdevelop. I use pthread library from linux to handle threads
and mutex. My question is how can my program detect if a thread struct
is still valid or active.... I use a library that call a function
pthread_kill (threadID,0) in order to detect if a thread is alive but
when the thread Id is invalid, it causes a segmentation fault.
Last time I looked, pthread_t on Linux was an opaque type, a pointer to
an internal struct. So it may be non-null and still invalid.
Ex:
if (threadID==0)
return FALSE;

Try to avoid nasty macros like TRUE and FALSE.

Ian
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.