--- libaitsched/src/hooks.c 2012/08/22 13:37:23 1.14.2.2 +++ libaitsched/src/hooks.c 2012/08/22 23:43:36 1.14.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.14.2.2 2012/08/22 13:37:23 misho Exp $ +* $Id: hooks.c,v 1.14.2.3 2012/08/22 23:43:36 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -209,7 +209,14 @@ sched_hook_cancel(void *task, void *arg __unused) #endif case taskTHREAD: #ifdef HAVE_LIBPTHREAD - pthread_cancel((pthread_t) TASK_VAL(t)); + /* try to wait for valid thread id */ + for (i = 0; i < MAX_TASK_MISS && + pthread_kill((pthread_t) TASK_VAL(t), 0); i++) + usleep(10); + /* try to sure thread is cancelled */ + for (i = 0; i < MAX_TASK_MISS && + !pthread_kill((pthread_t) TASK_VAL(t), 0); i++) + pthread_cancel((pthread_t) TASK_VAL(t)); if (TASK_FLAG(t) == PTHREAD_CREATE_JOINABLE) /* joinable thread */ schedTask(TASK_ROOT(t), _sched_threadJoin, TASK_ARG(t), TASK_VAL(t), TASK_DATA(t), TASK_DATLEN(t)); @@ -249,12 +256,12 @@ sched_hook_thread(void *task, void *arg) pthread_sigmask(SIG_SETMASK, &os, NULL); return (void*) -1; } - pthread_sigmask(SIG_SETMASK, &os, NULL); if (!TASK_ISLOCKED(t)) TASK_LOCK(t); TASK_VAL(t) = (u_long) tid; + pthread_sigmask(SIG_SETMASK, &os, NULL); return NULL; } #endif