[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Review Request: Do not terminate threads
From: "Albert Astals Cid" <tsdgeos () terra ! es>
Date: 2011-08-11 10:32:56
Message-ID: 20110811103256.13701.93069 () vidsolbach ! de
[Download RAW message or body]
> On Aug. 11, 2011, 9:41 a.m., David Faure wrote:
> > kio/kio/hostinfo.cpp, line 236
> > <http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line236>
> >
> > Maybe move nameLookupThread as a member of hostInfoAgentPrivate, to avoid \
> > multiplying the global statics (and therefore have more control over order of \
> > destruction)? Or does this make no sense?
Could make that, but they seem somewhat separate things to me so i'd prefer to keep \
them separate unless you have a strong feeling about it
> On Aug. 11, 2011, 9:41 a.m., David Faure wrote:
> > kio/kio/hostinfo.cpp, line 224
> > <http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line224>
> >
> > You could also just create the worker on the stack here.
Done
> On Aug. 11, 2011, 9:41 a.m., David Faure wrote:
> > kio/kio/hostinfo.cpp, line 179
> > <http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line179>
> >
> > reviewboard is highlighting quite a number of lines with trailing whitespace
Fixed
> On Aug. 11, 2011, 9:41 a.m., David Faure wrote:
> > kio/kio/hostinfo.cpp, line 266
> > <http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line266>
> >
> > Ouch, a busy loop.
> >
> > The standard solution is to use ... yes ... a semaphore :-) I love semaphores.
> >
> > Acquire the semaphore here, release it in the thread once the worker object has \
> > been created.
Changed.
> On Aug. 11, 2011, 9:41 a.m., David Faure wrote:
> > kio/kio/hostinfo.cpp, line 177
> > <http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line177>
> >
> > The interesting question is, what if hostname was already in the m_lookups map?
> >
> > Either we want to detect this upfront and not create a second request, or we need \
> > a "list of requests for a given hostname" in the map.
Found out i can actually use the request id as key so we should not have this problem \
now.
- Albert
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/102179/#review5623
-----------------------------------------------------------
On Aug. 11, 2011, 10:32 a.m., Albert Astals Cid wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/102179/
> -----------------------------------------------------------
>
> (Updated Aug. 11, 2011, 10:32 a.m.)
>
>
> Review request for kdelibs and Dawit Alemayehu.
>
>
> Summary
> -------
>
> Each time the terminate code triggers my Konqueror crashes, i'm substituting the \
> terminate for just waiting the thread to finish and we just ignoring it.
> The code has a race condition in which wait() returns false, then we switch to the \
> thread and m_autoDelete is still not set and thus noone will delete the thread. I \
> can add a mutex if you guys think this is unacceptable.
>
> Diffs
> -----
>
> kio/kio/hostinfo.cpp 344b1d8
>
> Diff: http://git.reviewboard.kde.org/r/102179/diff
>
>
> Testing
> -------
>
> When the
> kDebug() << "Name look up for" << hostName << "failed";
> if triggers i do not get a crash anymore.
>
>
> Thanks,
>
> Albert
>
>
[Attachment #3 (text/html)]
<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;"> <tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="http://git.reviewboard.kde.org/r/102179/">http://git.reviewboard.kde.org/r/102179/</a>
</td>
</tr>
</table>
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On August 11th, 2011, 9:41 a.m., <b>David \
Faure</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line177" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kio/kio/hostinfo.cpp</a> <span style="font-weight: normal;">
(Diff revision 5)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
">namespace KIO</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">172</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> \
<span class="n">m_lookups</span><span class="p">[</span><span \
class="n">hostName</span><span class="p">]</span> <span class="o">=</span> <span \
class="n">petition</span><span class="p">;</span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">The interesting question \
is, what if hostname was already in the m_lookups map?
Either we want to detect this upfront and not create a second request, or we need a \
"list of requests for a given hostname" in the map.</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Found out i \
can actually use the request id as key so we should not have this problem now.</pre> \
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On August 11th, 2011, 9:41 a.m., <b>David \
Faure</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line179" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kio/kio/hostinfo.cpp</a> <span style="font-weight: normal;">
(Diff revision 5)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
">namespace KIO</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">174</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="ew"> </span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">reviewboard is \
highlighting quite a number of lines with trailing whitespace</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Fixed</pre> \
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On August 11th, 2011, 9:41 a.m., <b>David \
Faure</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line224" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kio/kio/hostinfo.cpp</a> <span style="font-weight: normal;">
(Diff revision 5)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
">namespace KIO</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">219</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> \
<span class="n">m_worker</span> <span class="o">=</span> <span class="k">new</span> \
<span class="n">NameLookUpThreadWorker</span><span class="p">();</span></pre></td> \
</tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">You could also just \
create the worker on the stack here.</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Done</pre> \
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On August 11th, 2011, 9:41 a.m., <b>David \
Faure</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line236" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kio/kio/hostinfo.cpp</a> <span style="font-weight: normal;">
(Diff revision 5)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">K_GLOBAL_STATIC(NameLookUpThread, nameLookUpThread)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">231</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="n">K_GLOBAL_STATIC</span><span class="p">(</span><span \
class="n">NameLookUpThread</span><span class="p">,</span> <span \
class="n">nameLookUpThread</span><span class="p">)</span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Maybe move \
nameLookupThread as a member of hostInfoAgentPrivate, to avoid multiplying the global \
statics (and therefore have more control over order of destruction)? Or does this \
make no sense?</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Could make \
that, but they seem somewhat separate things to me so i'd prefer to keep them \
separate unless you have a strong feeling about it</pre> <br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On August 11th, 2011, 9:41 a.m., <b>David \
Faure</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102179/diff/5/?file=31680#file31680line266" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kio/kio/hostinfo.cpp</a> <span style="font-weight: normal;">
(Diff revision 5)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">K_GLOBAL_STATIC(NameLookUpThread, nameLookUpThread)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th> <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">259</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">while</span> <span class="p">(</span><span class="o">!</span><span \
class="n">nameLookUpThread</span><span class="o">-></span><span \
class="n">worker</span><span class="p">())</span> <span class="n">QThread</span><span \
class="o">::</span><span class="n">yieldCurrentThread</span><span \
class="p">();</span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Ouch, a busy loop.
The standard solution is to use ... yes ... a semaphore :-) I love semaphores.
Acquire the semaphore here, release it in the thread once the worker object has been \
created.</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Changed.</pre> <br />
<p>- Albert</p>
<br />
<p>On August 11th, 2011, 10:32 a.m., Albert Astals Cid wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://git.reviewboard.kde.org/media/rb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;"> <tr>
<td>
<div>Review request for kdelibs and Dawit Alemayehu.</div>
<div>By Albert Astals Cid.</div>
<p style="color: grey;"><i>Updated Aug. 11, 2011, 10:32 a.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Each time the terminate code triggers my Konqueror crashes, i'm \
substituting the terminate for just waiting the thread to finish and we just ignoring \
it.
The code has a race condition in which wait() returns false, then we switch to the \
thread and m_autoDelete is still not set and thus noone will delete the thread. I can \
add a mutex if you guys think this is unacceptable.</pre> </td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">When the kDebug() << "Name look up for" << \
hostName << "failed"; if triggers i do not get a crash anymore.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>kio/kio/hostinfo.cpp <span style="color: grey">(344b1d8)</span></li>
</ul>
<p><a href="http://git.reviewboard.kde.org/r/102179/diff/" style="margin-left: \
3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic