Re: [PATCH v2] threaded pack-objects: Use condition variables for thread communication.
I just discovered a theoretical resource leakage:
> + /* Partition the work amongst work threads. */
> for (i = 0; i < delta_search_threads; i++) {> + pthread_mutex_init(&p[i].mutex, NULL);
> + pthread_cond_init(&p[i].cond, NULL);
These two initializations...
Show 6 quoted lines
> }
>
> + /* Start work threads. */
> + for (i = 0; i < delta_search_threads; i++) {
> + if (!p[i].list_size)
> + continue;... should go here because...
Show 6 quoted lines
> + ret = pthread_create(&p[i].thread, NULL,
> + threaded_find_deltas, &p[i]);
> + if (ret)
> + die("unable to create thread: %s", strerror(ret));
> + active_threads++;
> + }> + while (active_threads) {> if (!sub_size) {
> pthread_join(target->thread, NULL);
> + pthread_cond_destroy(&target->cond);
> + pthread_mutex_destroy(&target->mutex);... we tear down only those for which we actually started a thread.
> active_threads--;
> }
> + }
Will send a patch this evening.
-- Hannes