Hey Sebastian<br><br><div class="gmail_quote">On Sun, May 23, 2010 at 7:06 PM, Sebastian Trüg <span dir="ltr">&lt;<a href="mailto:trueg@kde.org">trueg@kde.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Vishesh,<br>
<div class="im"><br>
On 05/23/2010 02:28 PM, Vishesh Handa wrote:<br>
&gt;<br>
&gt; Hey Sebastian<br>
&gt;<br>
&gt;     least one problem: run the resourcetest and see it crashing. This is due<br>
&gt;     to determineUri deleting &quot;this&quot;. determineUri() is called all over the<br>
&gt;     place. I think the one solution is to move that call into Resource as I<br>
&gt;     already did with store().<br>
&gt;<br>
&gt;<br>
&gt; I had no idea there were tests. For some reason I totally missed them! I<br>
&gt; was going to write my own tests to validate the patch.<br>
&gt;<br>
&gt; Anyway, you&#39;re right. It crashes. The problem is that replaceWith(..)<br>
&gt; deletes itself. And then determineUri tries to access the m_uri<br>
&gt; variable. Even if we simply &quot;return true&quot;, from determineUri(). It is<br>
&gt; called all over the place and hence some other member function accesses<br>
&gt; its, no longer valid, member variables. (Your explanation wasn&#39;t clear<br>
&gt; enough!)<br>
&gt;<br>
&gt; There is one more problem. I can&#39;t always reproduce it. Before<br>
&gt; replaceWith(..) is called the ResourceManager&#39;s mutex is locked. Then<br>
&gt; when deleting it self resetSelf(bool) attempts to lock the mutex. The<br>
&gt; locking sometimes fails, and it just keeps waiting.<br>
&gt;<br>
&gt; One way of solving both the problems is to derive ResourceData from<br>
&gt; QObject. And then call deleteLater() instead of &quot;delete this&quot;. (Patch<br>
&gt; attached)<br>
<br>
</div>oh, no, please don&#39;t. Totally useless overhead. It is much simpler to<br>
make the mutex recursive.<br>
<br></blockquote><div><br>Well then we need a better way of solving the &quot;delete this&quot; problem. When you say moving &quot;it&quot; into Resource, do you mean determineUri() or replaceWith() ? <br></div><div><br>
- Vishesh Handa<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
&gt; *Random Question:* In determineUri()&#39;s last if condition -<br>
<div class="im">&gt;<br>
&gt; if( !m_uri.isEmpty() ) {<br>
&gt;             QMutexLocker rmlock(&amp;m_rm-&gt;mutex);<br>
&gt;<br>
&gt;             ResourceDataHash::iterator it =<br>
&gt; m_rm-&gt;m_initializedData.find(m_uri);<br>
&gt;             if( it == m_rm-&gt;m_initializedData.end() ) {<br>
&gt;                 m_rm-&gt;m_initializedData.insert( m_uri, this );<br>
&gt;             }<br>
&gt;             else {<br>
&gt;                 // As the ResourceData already exists in<br>
&gt; m_initializedData, we simply<br>
&gt;                 // make all the the Resources which contain &quot;this&quot;<br>
&gt; ResourceData, point<br>
&gt;                 // to the initialized ResourceData instead.<br>
&gt;                 replaceWith( it.value() );<br>
&gt;             }<br>
&gt;         }<br>
&gt;<br>
&gt; Couldn&#39;t we move the MutexLocker inside the if( it ==<br>
&gt; m_rm-&gt;m_initializedData.end() ) ?<br>
<br>
</div>no, that is not possible since m_initializedData could change while the<br>
mutex is not locked. Thus, we need to make sure we iterate while locking.<br>
<br>
Cheers,<br>
<font color="#888888">Sebastian<br>
</font></blockquote></div><br>