On Sat, 22 Mar 2003 04:17 pm, Amanda Wynne wrote:
 timeout 25442 return 0

>
> When it stops, it looks like this:
> pid reading 0 return 0
> pid timeout 25444 return -1
>

Well the pid value is clearly incorrect, (no such pid as zero) suggesting that 
the call to pthread_create failed. You may want to check the return value 
from both calls to pthread_create, although since 
Mbm_get_data() and Mbm_sleep() both print to stderr when Mb_verbose is true, 
that may not be necessary. (This should be checked anyway, so maybe the 
library maintainer would like a patch?)

The man page says that pthread_create will fail if more than 
PTHREAD_THREADS_MAX threads are active, you could check what this value is 
defined to by grepping in /usr/include or wherever the system headers are if 
you are cross-compiling.

The failure of pthread_create seems related to the fact that the function uses 
pthread_cancel, which (I think) will not release the resources from the 
created threads, instead pthread_join should be used (maybe in addition to 
pthread_cancel). From the pthread_join manpage:

"When  a  joinable  thread  terminates,  its  memory  resources  (thread
descriptor and stack) are not deallocated until another thread performs
pthread_join on it. Therefore, pthread_join must  be  called  once  for
each joinable thread created to avoid memory leaks."

The two threads in this case are definitely "joinable".

You know life has taken a strange turn when you're debugging someone *else's* 
code on a Saturday night :-P




-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to