| 67 | bool active() |
| 68 | { |
| 69 | std::unique_lock<std::mutex> lock(m_mutex); |
| 70 | if (m_worker_list.empty()) return false; |
| 71 | return !m_worker_list.back()->m_stop; |
| 72 | } |
| 73 | |
| 74 | template<class QiWorkers, class ...Args> |
| 75 | void start(Args&&... args) |
| 76 | { |
| 77 | std::unique_lock<std::mutex> lock(m_mutex); |
| 78 | for (auto& i : m_worker_list) i->m_stop = true; |
| 79 | |
| 80 | auto& worker = m_worker_list.emplace_back(new QiWorkers(std::forward<Args>(args)...)); |
| 81 | std::thread([worker_refcopy = worker] { worker_refcopy->run(); worker_refcopy->m_stop = true; }).detach(); |
| 82 | |
| 83 | bool exist = false; |
| 84 | do { |
| 85 | exist = false; |
| 86 | for (auto i = m_worker_list.begin(); i != m_worker_list.end(); i++) |
| 87 | { |
| 88 | if ((*i)->m_stop) |
| 89 | { |
| 90 | m_worker_list.erase(i); |
| 91 | exist = true; |
| 92 | break; |
| 93 | } |