Join cancelled threads so we don't leak memory

master
Nick Krichevsky 2019-09-23 16:51:04 -04:00
parent b5484f115f
commit 0403e2cd75
1 changed files with 3 additions and 3 deletions

6
main.c
View File

@ -83,6 +83,7 @@ static int get_input(int num_threads, struct input **res) {
static void kill_threads(pthread_t *threads, int num_threads) {
for (int i = 0; i < num_threads; i++) {
pthread_cancel(threads[i]);
pthread_join(threads[i], NULL);
}
}
@ -279,12 +280,11 @@ int main(int argc, char *argv[]) {
}
int join_result = join_adder_threads(adder_threads, num_adder_threads);
if (join_result == 0) {
pthread_join(collect_thread, NULL);
} else {
if (join_result != 0) {
// If one of the joins failed, we have to tell the collection thread we're done.
pthread_cancel(collect_thread);
}
pthread_join(collect_thread, NULL);
free_mailboxes();
}