summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-21 08:59:26 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-21 08:59:26 +0100
commitcc920b4cddc170a7442d8fdfb53076c208a3d71e (patch)
treee4757cffe420bd3c61dda1d369b452a0fac9eff7 /tests/auto/corelib/thread
parentc8c8cc790a315710b0dae2282dc32e3472e107ee (diff)
parentfc8fd508165c8e4dcfe0da397b63cf99f15178e3 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
index a67ecc2471..b7134d0454 100644
--- a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
+++ b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
@@ -37,6 +37,8 @@ class tst_QSemaphore : public QObject
Q_OBJECT
private slots:
void acquire();
+ void multiRelease();
+ void multiAcquireRelease();
void tryAcquire();
void tryAcquireWithTimeout_data();
void tryAcquireWithTimeout();
@@ -149,6 +151,73 @@ void tst_QSemaphore::acquire()
QCOMPARE(semaphore.available(), 0);
}
+void tst_QSemaphore::multiRelease()
+{
+ class Thread : public QThread
+ {
+ public:
+ QSemaphore &sem;
+ Thread(QSemaphore &sem) : sem(sem) {}
+
+ void run() override
+ {
+ sem.acquire();
+ }
+ };
+
+ QSemaphore sem;
+ QVector<Thread *> threads;
+ threads.resize(4);
+
+ for (Thread *&t : threads)
+ t = new Thread(sem);
+ for (Thread *&t : threads)
+ t->start();
+
+ // wait for all threads to reach the sem.acquire() and then
+ // release them all
+ QTest::qSleep(1);
+ sem.release(threads.size());
+
+ for (Thread *&t : threads)
+ t->wait();
+ qDeleteAll(threads);
+}
+
+void tst_QSemaphore::multiAcquireRelease()
+{
+ class Thread : public QThread
+ {
+ public:
+ QSemaphore &sem;
+ Thread(QSemaphore &sem) : sem(sem) {}
+
+ void run() override
+ {
+ sem.acquire();
+ sem.release();
+ }
+ };
+
+ QSemaphore sem;
+ QVector<Thread *> threads;
+ threads.resize(4);
+
+ for (Thread *&t : threads)
+ t = new Thread(sem);
+ for (Thread *&t : threads)
+ t->start();
+
+ // wait for all threads to reach the sem.acquire() and then
+ // release them all
+ QTest::qSleep(1);
+ sem.release();
+
+ for (Thread *&t : threads)
+ t->wait();
+ qDeleteAll(threads);
+}
+
void tst_QSemaphore::tryAcquire()
{
QSemaphore semaphore;