/** * Terminates all running threads in the given group. * * @param[in] group thread group * @see hythread_cancel */ IDATA VMCALL hythread_cancel_all(hythread_group_t group) { hythread_iterator_t iter; hythread_t next; hythread_t self = tm_self_tls; if (!group) { group = TM_DEFAULT_GROUP; } iter = hythread_iterator_create(group); while ((next = hythread_iterator_next (&iter)) != NULL) { if (next != self) { hythread_cancel(next); //since this method being used at shutdown it does not //make any sense to exit on error, but continue terminating threads } } hythread_iterator_release(&iter); return TM_ERROR_NONE; }
ncaiError JNICALL ncaiTerminateThread(ncaiEnv *env, ncaiThread thread) { TRACE2("ncai.thread", "TerminateThread called"); SuspendEnabledChecker sec; if (env == NULL) return NCAI_ERROR_INVALID_ENVIRONMENT; if (thread == NULL) return NCAI_ERROR_INVALID_THREAD; hythread_t hythread = reinterpret_cast<hythread_t>(thread); hythread_t self = hythread_self(); if (hythread == self) return NCAI_ERROR_INVALID_THREAD; assert(thread); // grab hythread global lock hythread_global_lock(); if (!ncai_thread_is_alive(hythread)) { hythread_global_unlock(); return NCAI_ERROR_THREAD_NOT_ALIVE; } IDATA UNUSED status = jthread_vm_detach(jthread_get_vm_thread(hythread)); assert(status == TM_ERROR_NONE); hythread_cancel(hythread); // release hythread global lock hythread_global_unlock(); return NCAI_ERROR_NONE; }