<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 18, 2018 at 4:39 AM, Manohara Hosakoppa Krishnamurt via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">









<div>
<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" target="_blank">https://github.com/Samsung/<wbr>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<__<wbr>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<__<wbr>thread_struct> is not getting constructed in __thread_local_data().</p>
<p>__thread_local_data()         <wbr>                              <wbr>                     <br>{                             <wbr>                              <wbr>                     <br>    static __thread_specific_ptr<__<wbr>thread_struct> __p;                           <br>    return __p;                          <wbr>                              <wbr>      <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></div></blockquote><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br class="gmail-Apple-interchange-newline">__thread_specific_ptr intentionally leaks. See <a href="https://github.com/llvm-mirror/libcxx/blob/master/include/thread#L189">https://github.com/llvm-mirror/libcxx/blob/master/include/thread#L189</a></div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<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="m_723327727297999446bannersignimg"><tbody><tr><td><div id="m_723327727297999446cafe-note-contents" style="margin:10px;font-family:Arial;font-size:10pt"><p> </p></div></td></tr></tbody></table><table id="m_723327727297999446confidentialsignimg"><tbody><tr><td><div id="m_723327727297999446cafe-note-contents" style="margin:10px;font-family:Arial;font-size:10pt"><p><img 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></tbody></table></div><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"><br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>