android ndk thread,c-pthread_cancel()替代在Android NDK?
可能的选择,适用于这个家伙:http://igourd.blogspot.com/2009/05/work-around-on-pthreadcancel-for.html在这里转载:Then I use pthread_kill to trigger aSIG_USR1 signal and use signal handlerto exit this pthread and tried it,
可能的选择,适用于这个家伙:
http://igourd.blogspot.com/2009/05/work-around-on-pthreadcancel-for.html
在这里转载:
Then I use pthread_kill to trigger a
SIG_USR1 signal and use signal handler
to exit this pthread and tried it, it
works, but still wondering if any
drawbacks for this kind of method.
定时器:
if ( (status = pthread_kill(pthread_id, SIGUSR1)) != 0)
{
printf("Error cancelling thread %d, error = %d (%s)", pthread_id, status, strerror status));
}
USR1处理程序
struct sigaction actions;
memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_handler = thread_exit_handler;
rc = sigaction(SIGUSR1,&actions,NULL);
void thread_exit_handler(int sig)
{
printf("this signal is %d \n", sig);
pthread_exit(0);
}
更多推荐
所有评论(0)