virtual void read(Output& output) { GlobalLock::LockGuard guard(shared_.global_lock()); output.ok("list"); std::list<ManagedThread*>* thrs = shared_.threads(); output.e().write_tuple(thrs->size()); for(std::list<ManagedThread*>::iterator i = thrs->begin(); i != thrs->end(); i++) { ManagedThread* thr = *i; if(VM* vm = thr->as_vm()) { std::ostringstream ss; vm->saved_call_frame()->print_backtrace(state_, ss); output.e().write_tuple(3); output.e().write_atom("user"); output.e().write_atom(RTEST(vm->thread->sleep()) ? "sleep" : "run"); output.e().write_binary(ss.str().c_str()); } else { output.e().write_tuple(2); output.e().write_atom("system"); output.e().write_binary(thr->name()); } } }
void ManagedThread::abort(bool* flag,bool delete_thread) { if (!flag) return; // 1) Send signal to threads telling to terminate ASAP if (count_running() > 0) { *flag = true; wxMilliSleep(50); } // 2) Delete thread objects ManagedThread* thread; for (unsigned int i = 0; i < count_threads();++i) { thread = GetThread(i); if (!thread) continue; if (thread->get_abort_location()!=flag) continue; if (thread->IsAlive()) thread->Delete(); if (delete_thread) delete thread; } // 4) Reset the abort flag now that no associated threads are running *flag = false; }
bool SharedState::stop_the_world(THREAD) { bool stopped = world_->wait_til_alone(state); if(!stopped) return stopped; // Verify that everyone is stopped and we're alone. for(std::list<ManagedThread*>::iterator i = threads_.begin(); i != threads_.end(); i++) { ManagedThread *th = *i; switch(th->run_state()) { case ManagedThread::eAlone: if(th != state) { rubinius::bug("Tried to stop but someone else is alone!"); } break; case ManagedThread::eRunning: rubinius::bug("Tried to stop but threads still running!"); break; case ManagedThread::eSuspended: case ManagedThread::eIndependent: // Ok, this is fine. break; } } return true; }
void GarbageCollector::verify(GCData* data) { if(data->threads()) { for(ThreadList::iterator i = data->threads()->begin(); i != data->threads()->end(); ++i) { ManagedThread* thr = *i; for(Roots::Iterator ri(thr->roots()); ri.more(); ri.advance()) { ri->get()->validate(); } if(VM* vm = thr->as_vm()) { vm->gc_verify(this); } } } }
void ManagedThread::abort_all() { // 1) Send signal to threads telling to terminate ASAP if(count_running() > 0) { ManagedThread::s_abort_all = true; while(count_running() > 0) { wxMilliSleep(5); } wxMilliSleep(50); // (there's a tiny delay between the thread disminishing the count // and the thread actually stopping) // 50 ms should be more than enough } // 2) Delete thread objects ManagedThread *thread; for(unsigned int i = 0; i < count_threads();++i) { thread = GetThread(i); if(thread) { if(thread->IsAlive()) { thread->Delete(); } delete thread; } } // 3) Clear thread list wxCriticalSectionLocker lock(ManagedThread::s_list_mutex); s_threadslist.Clear(); // 4) Reset the abort flag now that no threads are running ManagedThread::s_abort_all = false; }