llvmpipe: Check thread creation errors
authorNathan Kidd <nkidd@opentext.com>
Fri, 15 Nov 2019 01:35:11 +0000 (02:35 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Fri, 15 Nov 2019 01:43:22 +0000 (02:43 +0100)
In the case of glibc, pthread_t is internally a pointer.  If
lp_rast_destroy() passes a 0-value pthread_t to pthread_join(), the
latter will SEGV dereferencing it.

pthread_create() can fail if either the user's ulimit -u or Linux
kernel's /proc/sys/kernel/threads-max is reached.

Choosing to continue, rather than fail, on theory that it is better to
run with the one main thread, than not run at all.

Keeping as many threads as we got, since lack of threads severely
degrades llvmpipe performance.

Signed-off-by: Nathan Kidd <nkidd@opentext.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/drivers/llvmpipe/lp_rast.c

index d50e92b2b61a01da14da010451f2654dbdcd3566..ef783ea6fb1b6782590c33d7159784d954444c4a 100644 (file)
@@ -867,6 +867,10 @@ create_rast_threads(struct lp_rasterizer *rast)
       pipe_semaphore_init(&rast->tasks[i].work_done, 0);
       rast->threads[i] = u_thread_create(thread_function,
                                             (void *) &rast->tasks[i]);
+      if (!rast->threads[i]) {
+         rast->num_threads = i; /* previous thread is max */
+         break;
+      }
    }
 }