<div class="gmail_quote">On Wed, Dec 1, 2010 at 6:04 PM, Milian Wolff <span dir="ltr"><<a href="mailto:mail@milianw.de">mail@milianw.de</a>></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'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'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>
> commit bae38ceb983f7c7b0b66ca475dbfa689ace8313e<br>
> branch master<br>
> Author: David Nolden <<a href="mailto:david.nolden.kde@art-master.de">david.nolden.kde@art-master.de</a>><br>
> Date:   Wed Dec 1 17:53:52 2010 +0100<br>
><br>
>     Use pthread directly for the foreground mutex, potentially trying to<br>
> workaround a problem in the QMutex implementation which leads to a rare<br>
> deadlock. BUG: 252659<br>
><br>
> diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt<br>
> index 4fd1ec4..d832c85 100644<br>
> --- a/interfaces/CMakeLists.txt<br>
> +++ b/interfaces/CMakeLists.txt<br>
> @@ -49,7 +49,8 @@ target_link_libraries(kdevplatforminterfaces<br>
>          ${KDE4_KTEXTEDITOR_LIBS}<br>
>          ${KDE4_THREADWEAVER_LIBRARIES}<br>
>          ${QT_QTDESIGNER_LIBRARY}<br>
> -        ${KDE4_KROSSCORE_LIBS})<br>
> +        ${KDE4_KROSSCORE_LIBS}<br>
> +        rt)<br>
>  target_link_libraries(kdevplatforminterfaces LINK_INTERFACE_LIBRARIES<br>
>          ${KDE4_KPARTS_LIBS}<br>
>          ${KDE4_KTEXTEDITOR_LIBS}<br>
> diff --git a/interfaces/foregroundlock.cpp b/interfaces/foregroundlock.cpp<br>
> index ada7db9..4e3a73d 100644<br>
> --- a/interfaces/foregroundlock.cpp<br>
> +++ b/interfaces/foregroundlock.cpp<br>
> @@ -24,8 +24,65 @@<br>
><br>
>  using namespace KDevelop;<br>
><br>
> +#define USE_PTHREAD_MUTEX<br>
> +<br>
> +#ifdef USE_PTHREAD_MUTEX<br>
> +<br>
> +#include <pthread.h><br>
> +#include <time.h><br>
> +<br>
> +<br>
> +class SimplePThreadMutex {<br>
> +public:<br>
> +    SimplePThreadMutex() {<br>
> +        m_mutex = PTHREAD_MUTEX_INITIALIZER;<br>
> +        int result = pthread_mutex_init(&m_mutex, 0);<br>
> +        Q_ASSERT(result == 0);<br>
> +    }<br>
> +    ~SimplePThreadMutex() {<br>
> +        pthread_mutex_destroy(&m_mutex);<br>
> +    }<br>
> +    void lock() {<br>
> +        int result = pthread_mutex_lock(&m_mutex);<br>
> +        Q_ASSERT(result == 0);<br>
> +    }<br>
> +    void unlock() {<br>
> +        int result = pthread_mutex_unlock(&m_mutex);<br>
> +        Q_ASSERT(result == 0);<br>
> +    }<br>
> +    bool tryLock(int interval) {<br>
> +        if(interval == 0)<br>
> +        {<br>
> +            int result = pthread_mutex_trylock(&m_mutex);<br>
> +            return result == 0;<br>
> +        }else{<br>
> +            timespec abs_time;<br>
> +            clock_gettime(CLOCK_REALTIME, &abs_time);<br>
> +            abs_time.tv_nsec += interval * 1000000;<br>
> +            if(abs_time.tv_nsec >= 1000000000)<br>
> +            {<br>
> +                abs_time.tv_nsec -= 1000000000;<br>
> +                abs_time.tv_sec += 1;<br>
> +            }<br>
> +<br>
> +            int result = pthread_mutex_timedlock(&m_mutex, &abs_time);<br>
> +            return result == 0;<br>
> +        }<br>
> +    }<br>
> +<br>
> +private:<br>
> +    pthread_mutex_t m_mutex;<br>
> +};<br>
> +<br>
>  namespace {<br>
> +<br>
> +SimplePThreadMutex internalMutex;<br>
> +#else<br>
> +<br>
> +namespace {<br>
> +<br>
>  QMutex internalMutex;<br>
> +#endif<br>
>  QMutex tryLockMutex;<br>
>  QMutex waitMutex;<br>
>  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>