Project

General

Profile

Actions

Bug #307

closed

lttng-ust threads should be created in DETACHED state as they are never joined

Added by Michael Greene almost 12 years ago. Updated over 11 years ago.

Status:
Resolved
Priority:
Normal
Target version:
-
Start date:
07/16/2012
Due date:
% Done:

0%

Estimated time:

Description

When running the sample program or one of my programs, Valgrind reports the thread created in lttng_ust_init as leaked:

==19830== 320 bytes in 1 blocks are possibly lost in loss record 3 of 4
==19830==    at 0x4C279F2: calloc (vg_replace_malloc.c:467)
==19830==    by 0x4011874: _dl_allocate_tls (dl-tls.c:300)
==19830==    by 0x5E23B68: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==19830==    by 0x503A5E9: lttng_ust_init (lttng-ust-comm.c:907)
==19830==    by 0x400EB55: call_init.part.0 (dl-init.c:85)
==19830==    by 0x400EC2E: _dl_init (dl-init.c:52)
==19830==    by 0x40015E9: ??? (in /lib/x86_64-linux-gnu/ld-2.13.so)
==19830== 
==19830== 320 bytes in 1 blocks are possibly lost in loss record 4 of 4
==19830==    at 0x4C279F2: calloc (vg_replace_malloc.c:467)
==19830==    by 0x4011874: _dl_allocate_tls (dl-tls.c:300)
==19830==    by 0x5E23B68: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==19830==    by 0x503A613: lttng_ust_init (lttng-ust-comm.c:913)
==19830==    by 0x400EB55: call_init.part.0 (dl-init.c:85)
==19830==    by 0x400EC2E: _dl_init (dl-init.c:52)
==19830==    by 0x40015E9: ??? (in /lib/x86_64-linux-gnu/ld-2.13.so)

I have not been able to fix this problem. However, during the investigation of this problem, I noticed that the threads are being created in the default state but are never intended to be explicitly detached or joined. If pthread_detach or pthread_join is never called, the thread should be created with the PTHREAD_CREATE_DETACHED detach state so that their storage can be reclaimed when the thread terminates.

To be clear, this patch does not fix my problem with Valgrind, but it changes behavior to match the spec.


Files

Actions #1

Updated by Mathieu Desnoyers over 11 years ago

  • Status changed from New to Resolved
  • Assignee set to Mathieu Desnoyers

patch pulled into master:

commit 1879f67f1532fe1644a0657a5d52f063b43c0bf4
Author: Michael Greene <>
Date: Thu Aug 16 16:42:02 2012 -0400

Fix: threads should be created in DETACHED state
Signed-off-by: Michael Greene &lt;&gt;
Signed-off-by: Mathieu Desnoyers &lt;&gt;

and stable-2.0:

commit e63683c765cba41c0b140e283d2eb03523e4c57e
Author: Michael Greene <>
Date: Thu Aug 16 16:42:02 2012 -0400

Fix: threads should be created in DETACHED state
Signed-off-by: Michael Greene &lt;&gt;
Signed-off-by: Mathieu Desnoyers &lt;&gt;

As specified in this comment in the lttng-ust code, we let the OS teardown the thread on purpose. We might need a valgrind annotation for this eventually:

/*
 * Do NOT join threads: use of sys_futex makes it impossible to
 * join the threads without using async-cancel, but async-cancel
 * is delivered by a signal, which could hit the target thread
 * anywhere in its code path, including while the ust_lock() is
 * held, causing a deadlock for the other thread. Let the OS
 * cleanup the threads if there are stalled in a syscall.
*/

Thanks !

Mathieu

Actions

Also available in: Atom PDF