Detach worker threads upon creation

This commit is contained in:
Petar Kapriš 2025-10-07 20:22:42 +01:00
parent 2a3fee2c3f
commit ba685cc0ca

View file

@ -15,7 +15,6 @@
int32_t thread_count;
struct threadInfo {
pthread_t id;
int32_t index; // unique number from 0 to thread_count-1
bool drawing; // marks if we are currently drawing for a given thread
bool complete; // marks if the drawing that it was supposed to
@ -323,7 +322,9 @@ int main(int argc, char **argv)
// we set this before the thread starts so it points to a valid
// integer, if the thread fails to start, it will simply be
// overwritten by the same value in the next run of the loop
if (pthread_create(&threads[count].id, NULL, &writer_thread, &threads[count].index)) {
pthread_t id;
if (pthread_create(&id, NULL, &writer_thread, &threads[count].index)) {
pthread_detach(id);
fprintf(stderr, "Failed to create thread %d\n", i);
continue;
}