Join cancelled threads so we don't leak memory
parent
b5484f115f
commit
0403e2cd75
6
main.c
6
main.c
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue