Called on the main thread. Wait for all other threads to complete before exiting.
| 194 | |
| 195 | // Called on the main thread. Wait for all other threads to complete before exiting. |
| 196 | static void WaitForOtherThreads() |
| 197 | { |
| 198 | while (!s_threads.empty()) |
| 199 | { |
| 200 | std::vector<HANDLE> threadHandles; |
| 201 | for (auto it = s_threads.begin(); it != s_threads.end(); ++it) |
| 202 | { |
| 203 | threadHandles.push_back(it->second); |
| 204 | } |
| 205 | |
| 206 | HANDLE* handleArray = threadHandles.data(); |
| 207 | DWORD dwIndex = MsgWaitForMultipleObjects( |
| 208 | static_cast<DWORD>(threadHandles.size()), threadHandles.data(), FALSE, INFINITE, |
| 209 | QS_ALLEVENTS); |
| 210 | |
| 211 | if (dwIndex == WAIT_OBJECT_0 + threadHandles.size()) |
| 212 | { |
| 213 | MSG msg; |
| 214 | while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) |
| 215 | { |
| 216 | TranslateMessage(&msg); |
| 217 | DispatchMessage(&msg); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |