[KDevPlatform] bae38ce: Use pthread directly for the foreground mutex, pot

Aleix Pol aleixpol at kde.org
Thu Dec 2 23:24:36 UTC 2010


On Wed, Dec 1, 2010 at 6:04 PM, Milian Wolff <mail at 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 at 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 at milianw.de
> http://milianw.de
>
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
>
>
What happened with that one?

Aleix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20101203/2a561873/attachment.html>


More information about the KDevelop-devel mailing list