[sheepdog] [PATCH UPDATE] work: make short thread DETACHED

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Jul 3 12:22:27 CEST 2012


At Tue,  3 Jul 2012 17:38:41 +0800,
Liu Yuan wrote:
> 
> From: Liu Yuan <tailai.ly at taobao.com>
> 
> This is need to release pthread resource.
> 
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
>  update: check retval of pthread_detach()
> 
>  sheep/work.c |   15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/sheep/work.c b/sheep/work.c
> index 618c9dd..8a6dce4 100644
> --- a/sheep/work.c
> +++ b/sheep/work.c
> @@ -62,6 +62,12 @@ static void *run_short_thread(void *arg)
>  	struct short_work *sw = arg;
>  	eventfd_t value = 1;
>  	static uint64_t idx = 0;
> +	int err;
> +
> +	/* Tell runtime to release resources after termination */
> +	err = pthread_detach(pthread_self());
> +	if (err)
> +		panic("%s\n", strerror(err));

If we detach the thread just after it starts, isn't it better to
create it in a detached state using pthread_attr_setdetachstate?

Thanks,

Kazutaka



More information about the sheepdog mailing list