int reap_threads(torque_ctx *ctx){ int ret = 0; if(ctx->ev){ ret = reap_thread(ctx->ev->nexttid); } return ret; }
/** @brief Cleans up after a thread, optionally returning the status information * provided by the thread at the time of exit.. * * @param tid the target thread * @param statusp the value passed to thr exit() by the joined thread will be placed * in the location referenced by statusp. * @return returns zero on success, and a negative number on error. */ int thr_join( int tid, void **statusp ) { thread_t *thread; int self_tid; /* Join on the self, return error */ self_tid = gettid(); if(self_tid == tid) return ERROR; /* The thread is not created yet */ thread = get_thread_by_tid(tid); lprintf("root addr %p\n", thread->stack_base); if(thread == NULL) return ERROR; /* * Try to join the thread */ mutex_lock(&thread->thr_mutex); /* The thread is not joined, join it */ if (thread->join_thread == INVALID_THREAD){ thread->join_thread = self_tid; } /* The thread is joined, return error */ else{ mutex_unlock(&thread->thr_mutex); return ERROR; } /* If the thread is not exited, wait for it to exit */ if(thread->status != EXITED) cond_wait(&thread->exit_cond, &thread->thr_mutex); /* Get status */ if(statusp != NULL) *statusp = thread->exit_status; mutex_unlock(&thread->thr_mutex); lprintf("get join %p %d\n", thread->stack_base, (int)*statusp); /* Reap the thread item */ reap_thread(thread, tid); return OK; }