<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div>I found similar problems when getting an exclusive lock via unique_lock as well. I wrote this test code to reproduce.&nbsp;</div><div><br></div><div>I get the still-reachable problem if I use either the read() or the write() call (shared_lock or unique_lock).&nbsp;</div><div><br></div><div>Multiple calls to these functions &nbsp;did not increase the number of reachable bytes in the valgrind report.&nbsp;</div><div><br></div><div>I understand my previous use of adopt_lock was undefined (hence i've not used it here). Is my use as described by the code correct now ? If so, is this a bug ?</div><div><br></div><div>&lt;code&gt;</div><div>// boost-1.39.0</div><div><div>#include &lt;iostream&gt;</div><div>#include "boost/thread/locks.hpp"</div><div>#include "boost/thread/shared_mutex.hpp"</div><div><br></div><div><br></div><div>using namespace std
 ;</div><div><br></div><div>boost::shared_mutex &amp; get_mutex() {</div><div>&nbsp;&nbsp; &nbsp;static boost::shared_mutex global_lock;</div><div>&nbsp;&nbsp; &nbsp;return global_lock;</div><div>}</div><div><br></div><div>void write() {</div><div>&nbsp;&nbsp; &nbsp;boost::unique_lock&lt;boost::shared_mutex&gt; write_lock(get_mutex()) ;</div><div>&nbsp;&nbsp; &nbsp;std::cout &lt;&lt; "write" &lt;&lt; std::endl ;</div><div>}</div><div><br></div><div>void read() {</div><div>&nbsp;&nbsp; &nbsp;boost::shared_lock&lt;boost::shared_mutex&gt; read_lock(get_mutex()) ;</div><div>&nbsp;&nbsp; &nbsp;std::cout &lt;&lt; "read" &lt;&lt; std::endl ;</div><div>}</div><div><br></div><div>int main(int argc,char **argv) {</div><div>&nbsp;&nbsp; &nbsp;write() ; // LINE A</div><div>&nbsp;&nbsp; &nbsp;read() ; &nbsp;// LINE B</div><div>&nbsp;&nbsp; &nbsp;std::cout &lt;&lt; "done" &lt;&lt; std::endl ;</div><div>&nbsp;&nbsp; &nbsp;return 0
 ;</div><div>}</div><div>&lt;/code&gt;</div></div><div><br></div><br><div>--- On <b>Thu, 9/3/09, Steven Watanabe <i>&lt;watanabesj@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Steven Watanabe &lt;watanabesj@gmail.com&gt;<br>Subject: Re: [Boost-users] valgrind reports memory still reachable when using shared_lock and shared_mutex<br>To: boost-users@lists.boost.org<br>Date: Thursday, September 3, 2009, 7:01 AM<br><br><div class="plainMail">AMDG<br><br>Rajeev Rao wrote:<br>&gt;&nbsp; When using shared_mutex class with shared_lock. I see the following behavior<br>&gt;<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;boost::shared_lock&lt;boost::shared_mutex&gt; lock(m_mutex) ;<br>&gt;<br>&gt; When running valgrind<br>&gt;<br>&gt; ==32255== LEAK SUMMARY:<br>&gt; ==32255==&nbsp; &nbsp; definitely lost: 0 bytes in 0 blocks.<br>&gt; ==32255==&nbsp; &nbsp; &nbsp; possibly lost: 0 bytes
 in 0 blocks.<br>&gt; ==32255==&nbsp; &nbsp; still reachable: 8 bytes in 1 blocks.<br>&gt; ==32255==&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;suppressed: 0 bytes in 0 blocks.<br>&gt;<br>&gt; However, if I change the code<br>&gt; to&nbsp; &nbsp;&nbsp;&nbsp;boost::shared_lock&lt;boost::shared_mutex&gt; lock(m_mutex,boost::adopt_lock) ;<br>&gt; then the valgrind report goes away.<br><br>This is undefined behavior.&nbsp; From the documentation<br><br>shared_lock(Lockable &amp;&nbsp; m,boost::adopt_lock_t)<br>Precondition:<br>&nbsp; &nbsp; The current thread owns an exclusive lock on m.<br><br>&gt; I understand that there are valid cases to expect reachable memory at exit Should this be expected in this case ?<br>&gt;&nbsp;&nbsp;&nbsp;<br><br>Yes.&nbsp; This is not expected, and there is no obvious way to change it.<br><br>In Christ,<br>Steven Watanabe<br><br>P.S. Please start a new thread instead of replying to an unrelated <br>existing
 thread.<br><br>_______________________________________________<br>Boost-users mailing list<br><a ymailto="mailto:Boost-users@lists.boost.org" href="/mc/compose?to=Boost-users@lists.boost.org">Boost-users@lists.boost.org</a><br><a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br></div></blockquote></div></td></tr></table>