可能的选择,适用于这个家伙:

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);

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐