In article <400c5988$wineasy.se>,
Johan Lindh <getridofthis.se> wrote:
You really should try running under a debugger a bit. :) That'd tell
you that your counter isn't being changed in a bizarre way; instead,
it's ping-ponging back and forth as your two counter threads run.
As for why your count_down thread is continuing to run, that's because
your pbThreadDestroy() function is attempting to stop the thread by
calling pthread_cancel(). From Mac OS X's man page for pthread_cancel:
"The pthread_cancel() function requests that thread be canceled. The
target thread's cancelability state and type determines when the
cancellation takes effect."
In other words, pthread_cancel() is a request, not a requirement. In
general (as far as I know; I'm not a pthreads expert), pthreads are only
canceled on any system when they are at cancellation points. Mac OS X
currently has very few cancellation points for pthreads, so
pthread_cancel() essentially only has an impact if the canceled thread
calls pthread_testcancel(). Since your count_down thread doesn't call
pthread_testcancel(), it continues to run.
Hope this helps,
Eric Albert stanford.edu