In the case of an app returning from main(), Windows will apparently terminate
other threads before invoking final cleanup on the main thread.
llvmpipe can't wait for threads to signal a semaphore if the thread is already
gone. Since we're already in a WIN32 special case, just call the Win32 API
to check if the thread is terminated or STILL_ALIVE.
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12731>
* per https://bugs.freedesktop.org/show_bug.cgi?id=76252 */
for (i = 0; i < rast->num_threads; i++) {
#ifdef _WIN32
- pipe_semaphore_wait(&rast->tasks[i].work_done);
+ /* Threads might already be dead - Windows apparently terminates other threads when
+ * returning from main.
+ */
+ DWORD exit_code = STILL_ACTIVE;
+ if (GetExitCodeThread(rast->threads[i], &exit_code) && exit_code == STILL_ACTIVE)
+ pipe_semaphore_wait(&rast->tasks[i].work_done);
#else
thrd_join(rast->threads[i], NULL);
#endif