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

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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐