[cfe-dev] [Libcxx/TizenRT]: Memory leak in std::thread

Eric Fiselier via cfe-dev cfe-dev at lists.llvm.org
Sat May 19 00:00:49 PDT 2018


On Fri, May 18, 2018 at 4:39 AM, Manohara Hosakoppa Krishnamurt via cfe-dev
<cfe-dev at lists.llvm.org> wrote:

> Hello Everyone,
>
>
>
> We are using *LLVM libc++ *in TizenRT IoT OS( https://github.com/Samsung/
> TizenRT). We observed *memory leak while using std::thread*
>
>
>
> About TizenRT:
>
> LLVM libc++ source has been integrated to TizenRT and the whole
> platform(OS + libc + libcpp + App) is built into  a single elf executable.
>
> TizenRT uses a FLAT memory model(physical memory), there is no virtual
> memory support and hence we cant run application executables (elf) directly.
>
>
>
> First time when we create a thread using std::thread , there is no memory
> leak after thread exits.
>
> But next time onwards, if we create a thread using std::thread and after
> thread exits there is a memory leak.
>
>
>
> First time__thread_specific_ptr<__thread_struct> is constructed in
> __thread_local_data()  and hence the pthread_key_create() and during exit
> key is destroyed.
>
>
>
> But second time onwards, __thread_specific_ptr<__thread_struct> is not
> getting constructed in __thread_local_data().
>
> __thread_local_data()
>
> {
>
>     static __thread_specific_ptr<__thread_struct>
> __p;
>     return __p;
>
> }
>
>
>
> We suspect that the problem is with __thread_local_data(), and
> __thread_specific_ptr is getting constructed only once.
>
> Because of this we feel "__thread_struct  and __thread_struct_impl " which
> are allocated earlier during thread create are not getting freed and there
> is a leak.
>

__thread_specific_ptr intentionally leaks. See
https://github.com/llvm-mirror/libcxx/blob/master/include/thread#L189


>
>
> Please guide us with,  how can we deallocate these objects after or during
> thread exit.
>
> Also  what is the expected behavior of thread_local_data instance?
> 1. One thread_local_data instance for a process/task and all of its
> threads(pthreads) share the same thread_local_data instance?
>
> OR
> 2. Each thread(pthread) should have a separate thread_local_data instance?
>
>
>
> Thanks,
>
> Manohar
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180519/1d6b19c9/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 13402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180519/1d6b19c9/attachment.gif>


More information about the cfe-dev mailing list