| 128 | } |
| 129 | |
| 130 | void stopWorkerThreads(bool blocking = false) { |
| 131 | // Check if stop has been called already. |
| 132 | auto& executorHandle = threadLocalExecutorHandle(); |
| 133 | if (executorHandle.ptr == nullptr || hasStopped.exchange(true)) return; |
| 134 | |
| 135 | // now inject the null task as termination signal to every worker |
| 136 | for (auto& workerDeque : workerDeques) { |
| 137 | workerDeque->injectTaskAndNotify(nullptr); |
| 138 | } |
| 139 | |
| 140 | // only block if called on main thread, otherwise deadlock may occur |
| 141 | if (blocking && executorHandle.isMain) { |
| 142 | for (auto& workerThread : workerThreads) { |
| 143 | workerThread.join(); |
| 144 | } |
| 145 | } else { |
| 146 | for (auto& workerThread : workerThreads) { |
| 147 | workerThread.detach(); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | static HighsSplitDeque* getThisWorkerDeque() { |
| 153 | return threadLocalWorkerDeque(); |
no test coverage detected