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; }
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; }