[libvirt] [PATCH 4/6] virThreadPoolFree: Join worker threads

Martin Kletzander mkletzan at redhat.com
Thu Nov 14 11:40:37 UTC 2013


On Thu, Nov 14, 2013 at 10:51:14AM +0100, Michal Privoznik wrote:
> Even though currently we are freeing the pool of worker threads at the
> daemon very end, nothing holds us back in joining the worker threads.
> 

s/daemon/daemon's/ ???

Unless the thread is blocked, right?  Not that it should happen, but
maybe adding a wrapper for pthread_timedjoin_np and using that (if
available) might be better?  Just an idea, I haven't thought that
through ;)

> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/util/virthreadpool.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c
> index b1e2c0c..99f36ec 100644
> --- a/src/util/virthreadpool.c
> +++ b/src/util/virthreadpool.c
> @@ -241,6 +241,9 @@ void virThreadPoolFree(virThreadPoolPtr pool)
>  {
>      virThreadPoolJobPtr job;
>      bool priority = false;
> +    size_t i;
> +    size_t nWorkers = pool->nWorkers;
> +    size_t nPrioWorkers = pool->nPrioWorkers;
>  
>      if (!pool)
>          return;
> @@ -262,6 +265,12 @@ void virThreadPoolFree(virThreadPoolPtr pool)
>          VIR_FREE(job);
>      }
>  
> +    for (i = 0; i < nWorkers; i++)
> +        virThreadJoin(&pool->workers[i]);
> +
> +    for (i = 0; i < nPrioWorkers; i++)
> +        virThreadJoin(&pool->prioWorkers[i]);
> +
>      VIR_FREE(pool->workers);
>      virMutexUnlock(&pool->mutex);
>      virMutexDestroy(&pool->mutex);
> -- 
> 1.8.3.2
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131114/c0255e70/attachment-0001.sig>


More information about the libvir-list mailing list