Subject: Re: [PATCH v2] threaded pack-objects: Use condition variables for thread communication.

From: Johannes Sixt <[email-masked]>
Date: Mon, 17 Dec 2007 08:44:17 +0100

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...

>  	}
>  
> +	/* Start work threads. */
> +	for (i = 0; i < delta_search_threads; i++) {
> +		if (!p[i].list_size)
> +			continue;

... should go here because...

> +		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