<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>.search-word {
        BACKGROUND-COLOR: #ffee94
}
P {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 10pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
TD {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 10pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
LI {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 10pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
BODY {
        FONT-SIZE: 10pt; FONT-FAMILY: Arial, arial
}
</STYLE>

<META content=IE=5 http-equiv=X-UA-Compatible>
<META content=IE=5 http-equiv=X-UA-Compatible>
<STYLE id=knox_style type=text/css>P {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 10pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
</STYLE>

<META content=IE=5 http-equiv=X-UA-Compatible>
<META name=GENERATOR content="MSHTML 11.00.9600.18921"></HEAD>
<BODY>
<P>Hello Everyone,</P>
<P> </P>
<P>We are using <STRONG>LLVM libc++ </STRONG>in TizenRT IoT OS( <A href="https://github.com/Samsung/TizenRT">https://github.com/Samsung/TizenRT</A>). We observed <STRONG>memory leak while using std::thread</STRONG></P>
<P> </P>
<P>About TizenRT:</P>
<P>LLVM libc++ source has been integrated to TizenRT and the whole platform(OS + libc + libcpp + App) is built into  a single elf executable.</P>
<P>TizenRT uses a FLAT memory model(physical memory), there is no virtual memory support and hence we cant run application executables (elf) directly.</P>
<P> </P>
<P>First time when we create a thread using std::thread , there is no memory leak after thread exits.</P>
<P>But next time onwards, if we create a thread using std::thread and after thread exits there is a memory leak.</P>
<P> </P>
<P>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.</P>
<P> </P>
<P>But second time onwards, __thread_specific_ptr<__thread_struct> is not getting constructed in __thread_local_data().</P>
<P>__thread_local_data()                                                            <BR>{                                                                                <BR>    static __thread_specific_ptr<__thread_struct> __p;                           <BR>    return __p;                                                              <BR>}</P>
<P> </P>
<P>We suspect that the problem is with __thread_local_data(), and __thread_specific_ptr is getting constructed only once.</P>
<P>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.</P>
<P> </P>
<P>Please guide us with,  how can we deallocate these objects after or during thread exit.</P>
<P>Also  what is the expected behavior of thread_local_data instance?<BR>1. One thread_local_data instance for a process/task and all of its threads(pthreads) share the same thread_local_data instance?</P>
<P>OR<BR>2. Each thread(pthread) should have a separate thread_local_data instance?</P>
<P> </P>
<P>Thanks,</P>
<P>Manohar</P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P><table id=bannersignimg><tr><td><div id="cafe-note-contents" style="margin:10px;font-family:Arial;font-size:10pt;"><p> </p></div></td></tr></table><table id=confidentialsignimg><tr><td><div id="cafe-note-contents" style="margin:10px;font-family:Arial;font-size:10pt;"><p><img unselectable="on" data-cui-image="true" style="display: inline-block; border: 0px solid; width: 520px; height: 144px;" src="cid:cafe_image_0@s-core.co.kr"><br></p></div></td></tr></table></BODY></HTML><img src='http://ext.samsung.net/mail/ext/v1/external/status/update?userid=manohara.hk&do=bWFpbElEPTIwMTgwNTE4MTAzOTM3ZXBjbXM1cDFiZDE3NWE4MWJmNjAzMWY5ZjgzOGIxZDk4OTAzZWRmNCZyZWNpcGllbnRBZGRyZXNzPWNmZS1kZXZAbGlzdHMubGx2bS5vcmc_' border=0 width=0 height=0 style='display:none'>