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().
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.
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?
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?
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().
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.
If it is intentionally leaked, Is it freed at any later stage and who is responsible for cleanup?
Nothing; it’s leaked under the assumption that normal memory allocations will be returned to the OS at exit. This is a common technique used in language libraries and runtimes. It’s even considered good practice, at it allows the process to exit faster and eliminates a source of crashes during user-provided atexit() teardown. If Tizen doesn’t return process memory automatically, you will need to change the code when compiling for Tizen.