[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kdevelop-devel
Subject:    Re: [KDevPlatform] bae38ce: Use pthread directly for the foreground
From:       Aleix Pol <aleixpol () kde ! org>
Date:       2010-12-02 23:24:36
Message-ID: AANLkTikXUo0mz58rW2eKfrus1D2Dc0RZWC1NZmZSoheL () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Wed, Dec 1, 2010 at 6:04 PM, Milian Wolff <mail@milianw.de> wrote:

> Sorry David, but this is a no-go. Pthread is not cross-platform, and I
> still
> did not find a single reason for why this should be a QMutex bug. Why does
> that work for us in all other cases (and tons of other projects), but no
> here?
>
> Really, instead of putting work-around over work-around, we should dissect
> this problem and find the *real* reason.
>
> Doing guess-work won't help, and so far you only proposed that there
> *could*
> be a bug in QMutex, without
>
> a) explaining where the bug occurs
> b) reporting a bug to Nokia
>
> I'm heavily opposed to this, imo you should start to write unit tests and
> try
> to reproduce the deadlock before adding more workarounds.
>
> Bye
>
> David Nolden, 01.12.2010:
> > commit bae38ceb983f7c7b0b66ca475dbfa689ace8313e
> > branch master
> > Author: David Nolden <david.nolden.kde@art-master.de>
> > Date:   Wed Dec 1 17:53:52 2010 +0100
> >
> >     Use pthread directly for the foreground mutex, potentially trying to
> > workaround a problem in the QMutex implementation which leads to a rare
> > deadlock. BUG: 252659
> >
> > diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt
> > index 4fd1ec4..d832c85 100644
> > --- a/interfaces/CMakeLists.txt
> > +++ b/interfaces/CMakeLists.txt
> > @@ -49,7 +49,8 @@ target_link_libraries(kdevplatforminterfaces
> >          ${KDE4_KTEXTEDITOR_LIBS}
> >          ${KDE4_THREADWEAVER_LIBRARIES}
> >          ${QT_QTDESIGNER_LIBRARY}
> > -        ${KDE4_KROSSCORE_LIBS})
> > +        ${KDE4_KROSSCORE_LIBS}
> > +        rt)
> >  target_link_libraries(kdevplatforminterfaces LINK_INTERFACE_LIBRARIES
> >          ${KDE4_KPARTS_LIBS}
> >          ${KDE4_KTEXTEDITOR_LIBS}
> > diff --git a/interfaces/foregroundlock.cpp
> b/interfaces/foregroundlock.cpp
> > index ada7db9..4e3a73d 100644
> > --- a/interfaces/foregroundlock.cpp
> > +++ b/interfaces/foregroundlock.cpp
> > @@ -24,8 +24,65 @@
> >
> >  using namespace KDevelop;
> >
> > +#define USE_PTHREAD_MUTEX
> > +
> > +#ifdef USE_PTHREAD_MUTEX
> > +
> > +#include <pthread.h>
> > +#include <time.h>
> > +
> > +
> > +class SimplePThreadMutex {
> > +public:
> > +    SimplePThreadMutex() {
> > +        m_mutex = PTHREAD_MUTEX_INITIALIZER;
> > +        int result = pthread_mutex_init(&m_mutex, 0);
> > +        Q_ASSERT(result == 0);
> > +    }
> > +    ~SimplePThreadMutex() {
> > +        pthread_mutex_destroy(&m_mutex);
> > +    }
> > +    void lock() {
> > +        int result = pthread_mutex_lock(&m_mutex);
> > +        Q_ASSERT(result == 0);
> > +    }
> > +    void unlock() {
> > +        int result = pthread_mutex_unlock(&m_mutex);
> > +        Q_ASSERT(result == 0);
> > +    }
> > +    bool tryLock(int interval) {
> > +        if(interval == 0)
> > +        {
> > +            int result = pthread_mutex_trylock(&m_mutex);
> > +            return result == 0;
> > +        }else{
> > +            timespec abs_time;
> > +            clock_gettime(CLOCK_REALTIME, &abs_time);
> > +            abs_time.tv_nsec += interval * 1000000;
> > +            if(abs_time.tv_nsec >= 1000000000)
> > +            {
> > +                abs_time.tv_nsec -= 1000000000;
> > +                abs_time.tv_sec += 1;
> > +            }
> > +
> > +            int result = pthread_mutex_timedlock(&m_mutex, &abs_time);
> > +            return result == 0;
> > +        }
> > +    }
> > +
> > +private:
> > +    pthread_mutex_t m_mutex;
> > +};
> > +
> >  namespace {
> > +
> > +SimplePThreadMutex internalMutex;
> > +#else
> > +
> > +namespace {
> > +
> >  QMutex internalMutex;
> > +#endif
> >  QMutex tryLockMutex;
> >  QMutex waitMutex;
> >  QMutex finishMutex;
>
>
> --
> Milian Wolff
> mail@milianw.de
> http://milianw.de
>
> --
> KDevelop-devel mailing list
> KDevelop-devel@kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
>
>
What happened with that one?

Aleix

[Attachment #5 (text/html)]

<div class="gmail_quote">On Wed, Dec 1, 2010 at 6:04 PM, Milian Wolff <span dir="ltr">&lt;<a \
href="mailto:mail@milianw.de">mail@milianw.de</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> \
Sorry David, but this is a no-go. Pthread is not cross-platform, and I still<br> did not find a \
single reason for why this should be a QMutex bug. Why does<br> that work for us in all other \
cases (and tons of other projects), but no here?<br> <br>
Really, instead of putting work-around over work-around, we should dissect<br>
this problem and find the *real* reason.<br>
<br>
Doing guess-work won&#39;t help, and so far you only proposed that there *could*<br>
be a bug in QMutex, without<br>
<br>
a) explaining where the bug occurs<br>
b) reporting a bug to Nokia<br>
<br>
I&#39;m heavily opposed to this, imo you should start to write unit tests and try<br>
to reproduce the deadlock before adding more workarounds.<br>
<br>
Bye<br>
<br>
David Nolden, 01.12.2010:<br>
&gt; commit bae38ceb983f7c7b0b66ca475dbfa689ace8313e<br>
&gt; branch master<br>
&gt; Author: David Nolden &lt;<a \
href="mailto:david.nolden.kde@art-master.de">david.nolden.kde@art-master.de</a>&gt;<br> &gt; \
Date:    Wed Dec 1 17:53:52 2010 +0100<br> &gt;<br>
&gt;       Use pthread directly for the foreground mutex, potentially trying to<br>
&gt; workaround a problem in the QMutex implementation which leads to a rare<br>
&gt; deadlock. BUG: 252659<br>
&gt;<br>
&gt; diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt<br>
&gt; index 4fd1ec4..d832c85 100644<br>
&gt; --- a/interfaces/CMakeLists.txt<br>
&gt; +++ b/interfaces/CMakeLists.txt<br>
&gt; @@ -49,7 +49,8 @@ target_link_libraries(kdevplatforminterfaces<br>
&gt;               ${KDE4_KTEXTEDITOR_LIBS}<br>
&gt;               ${KDE4_THREADWEAVER_LIBRARIES}<br>
&gt;               ${QT_QTDESIGNER_LIBRARY}<br>
&gt; -            ${KDE4_KROSSCORE_LIBS})<br>
&gt; +            ${KDE4_KROSSCORE_LIBS}<br>
&gt; +            rt)<br>
&gt;   target_link_libraries(kdevplatforminterfaces LINK_INTERFACE_LIBRARIES<br>
&gt;               ${KDE4_KPARTS_LIBS}<br>
&gt;               ${KDE4_KTEXTEDITOR_LIBS}<br>
&gt; diff --git a/interfaces/foregroundlock.cpp b/interfaces/foregroundlock.cpp<br>
&gt; index ada7db9..4e3a73d 100644<br>
&gt; --- a/interfaces/foregroundlock.cpp<br>
&gt; +++ b/interfaces/foregroundlock.cpp<br>
&gt; @@ -24,8 +24,65 @@<br>
&gt;<br>
&gt;   using namespace KDevelop;<br>
&gt;<br>
&gt; +#define USE_PTHREAD_MUTEX<br>
&gt; +<br>
&gt; +#ifdef USE_PTHREAD_MUTEX<br>
&gt; +<br>
&gt; +#include &lt;pthread.h&gt;<br>
&gt; +#include &lt;time.h&gt;<br>
&gt; +<br>
&gt; +<br>
&gt; +class SimplePThreadMutex {<br>
&gt; +public:<br>
&gt; +      SimplePThreadMutex() {<br>
&gt; +            m_mutex = PTHREAD_MUTEX_INITIALIZER;<br>
&gt; +            int result = pthread_mutex_init(&amp;m_mutex, 0);<br>
&gt; +            Q_ASSERT(result == 0);<br>
&gt; +      }<br>
&gt; +      ~SimplePThreadMutex() {<br>
&gt; +            pthread_mutex_destroy(&amp;m_mutex);<br>
&gt; +      }<br>
&gt; +      void lock() {<br>
&gt; +            int result = pthread_mutex_lock(&amp;m_mutex);<br>
&gt; +            Q_ASSERT(result == 0);<br>
&gt; +      }<br>
&gt; +      void unlock() {<br>
&gt; +            int result = pthread_mutex_unlock(&amp;m_mutex);<br>
&gt; +            Q_ASSERT(result == 0);<br>
&gt; +      }<br>
&gt; +      bool tryLock(int interval) {<br>
&gt; +            if(interval == 0)<br>
&gt; +            {<br>
&gt; +                  int result = pthread_mutex_trylock(&amp;m_mutex);<br>
&gt; +                  return result == 0;<br>
&gt; +            }else{<br>
&gt; +                  timespec abs_time;<br>
&gt; +                  clock_gettime(CLOCK_REALTIME, &amp;abs_time);<br>
&gt; +                  abs_time.tv_nsec += interval * 1000000;<br>
&gt; +                  if(abs_time.tv_nsec &gt;= 1000000000)<br>
&gt; +                  {<br>
&gt; +                        abs_time.tv_nsec -= 1000000000;<br>
&gt; +                        abs_time.tv_sec += 1;<br>
&gt; +                  }<br>
&gt; +<br>
&gt; +                  int result = pthread_mutex_timedlock(&amp;m_mutex, &amp;abs_time);<br>
&gt; +                  return result == 0;<br>
&gt; +            }<br>
&gt; +      }<br>
&gt; +<br>
&gt; +private:<br>
&gt; +      pthread_mutex_t m_mutex;<br>
&gt; +};<br>
&gt; +<br>
&gt;   namespace {<br>
&gt; +<br>
&gt; +SimplePThreadMutex internalMutex;<br>
&gt; +#else<br>
&gt; +<br>
&gt; +namespace {<br>
&gt; +<br>
&gt;   QMutex internalMutex;<br>
&gt; +#endif<br>
&gt;   QMutex tryLockMutex;<br>
&gt;   QMutex waitMutex;<br>
&gt;   QMutex finishMutex;<br>
<font color="#888888"><br>
<br>
--<br>
Milian Wolff<br>
<a href="mailto:mail@milianw.de">mail@milianw.de</a><br>
<a href="http://milianw.de" target="_blank">http://milianw.de</a><br>
</font><br>--<br>
KDevelop-devel mailing list<br>
<a href="mailto:KDevelop-devel@kdevelop.org">KDevelop-devel@kdevelop.org</a><br>
<a href="https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel" \
target="_blank">https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel</a><br> \
<br></blockquote></div><br><div>What happened with that \
one?</div><div><br></div><div>Aleix</div>



-- 
KDevelop-devel mailing list
KDevelop-devel@kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic