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

List:       kdevelop-bugs
Subject:    [Bug 252659] deadlock due to ForegroundLock
From:       Milian Wolff <mail () milianw ! de>
Date:       2010-12-12 18:59:50
Message-ID: 20101212185950.B065077420 () immanuel ! kde ! org
[Download RAW message or body]

https://bugs.kde.org/show_bug.cgi?id=252659





--- Comment #14 from Milian Wolff <mail milianw de>  2010-12-12 19:59:45 ---

    A     interfaces/tests/test_foregroundlock.h     [License: UNKNOWN]


    A     interfaces/tests/test_foregroundlock.cpp     [License: UNKNOWN]


    A     interfaces/tests/CMakeLists.txt     [License: Trivialfile.]

commit c53cd44796c12304ccf71693e414c6a1c99be54c
Author: Milian Wolff <mail@milianw.de>
Date:   Sun Dec 12 19:58:31 2010 +0100

    add testcase for deadlock in ForegroundLock with QMutex

    comment out #define USE_PTHREAD_MUTEX in foregroundlock.cpp , then run the
testcase. Locks up reliably for me.
    With the alternative mutex it seems to work fine though.

    CCBUG: 252659

diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt
index 599c7fc..b7d9a0e 100644
--- a/interfaces/CMakeLists.txt
+++ b/interfaces/CMakeLists.txt
@@ -1,5 +1,7 @@
 find_package(Threads)

+add_subdirectory(tests)
+
 add_definitions( -DKDE_DEFAULT_DEBUG_AREA=9502 )
 set(kdevplatforminterfaces_LIB_SRCS
     foregroundlock.cpp
diff --git a/interfaces/tests/CMakeLists.txt b/interfaces/tests/CMakeLists.txt
new file mode 100644
index 0000000..ba5ebbc
--- /dev/null
+++ b/interfaces/tests/CMakeLists.txt
@@ -0,0 +1,5 @@
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+set(foregroundlock_SRC test_foregroundlock.cpp ../foregroundlock.cpp)
+kde4_add_unit_test(foregroundlocktest ${foregroundlock_SRC})
+target_link_libraries(foregroundlocktest ${KDE4_KDECORE_LIBS}
${QT_QTTEST_LIBRARY})
diff --git a/interfaces/tests/test_foregroundlock.cpp
b/interfaces/tests/test_foregroundlock.cpp
new file mode 100644
index 0000000..d47811b
--- /dev/null
+++ b/interfaces/tests/test_foregroundlock.cpp
@@ -0,0 +1,72 @@
+/* This file is part of KDevelop
+    Copyright 2010 Milian Wolff <mail@milianw.de>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License version 2 as published by the Free Software Foundation.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+*/
+
+#include "test_foregroundlock.h"
+
+#include <QtTest/QtTest>
+
+#include <QDebug>
+#include <QThread>
+
+#include <unistd.h>
+
+#include "../foregroundlock.h"
+
+QTEST_MAIN(KDevelop::TestForegroundLock)
+
+using namespace KDevelop;
+
+//BEGIN Helper Threads
+
+class TryLockThread : public QThread {
+    Q_OBJECT
+public:
+    virtual void run() {
+        ForegroundLock lock(false);
+        for(int i = 0; i < 1000; ++i) {
+            if (lock.tryLock()) {
+                lock.unlock();
+            }
+            usleep(qrand() % 20);
+        }
+    }
+};
+
+void TestForegroundLock::testTryLock()
+{
+    TryLockThread t1;
+    TryLockThread t2;
+    TryLockThread t3;
+
+    ForegroundLock lock(true);
+
+    t1.start();
+    t2.start();
+    t3.start();
+
+    lock.unlock();
+
+    while(t1.isRunning() || t2.isRunning() || t3.isRunning()) {
+        lock.relock();
+        usleep(10);
+        lock.unlock();
+    }
+}
+
+#include "moc_test_foregroundlock.cpp"
+#include "test_foregroundlock.moc"
diff --git a/interfaces/tests/test_foregroundlock.h
b/interfaces/tests/test_foregroundlock.h
new file mode 100644
index 0000000..9ce6b17
--- /dev/null
+++ b/interfaces/tests/test_foregroundlock.h
@@ -0,0 +1,34 @@
+/* This file is part of KDevelop
+    Copyright 2010 Milian Wolff <mail@milianw.de>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License version 2 as published by the Free Software Foundation.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with this library; see the file COPYING.LIB.  If not, write to
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+*/
+
+#ifndef TEST_FOREGROUNDLOCK_H
+#define TEST_FOREGROUNDLOCK_H
+
+#include <QObject>
+
+namespace KDevelop {
+class TestForegroundLock : public QObject {
+    Q_OBJECT
+
+private slots:
+    void testTryLock();
+};
+}
+
+
+#endif // TEST_FOREGROUNDLOCK_H

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

_______________________________________________
KDevelop-bugs mailing list
KDevelop-bugs@kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-bugs
[prev in list] [next in list] [prev in thread] [next in thread] 

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