Commit Graph

9 Commits

Author SHA1 Message Date
Jason E. Hale
6e0e6f3bc3
Fix build with Qt 6.9.0 (fixes #469)
Support for std::array was added to QDebug in 6.9.0
2025-04-19 06:28:17 -04:00
Igor Kushnir
05b384ed6d Make ConcurrentQueue::waitAll() const
This member function does not affect the logical state of the class.
Making std::condition_variable and std::mutex data members mutable is
idiomatic as these classes are thread-safe synchronization primitives.
2021-12-29 09:36:44 +01:00
Igor Kushnir
61cd245037 Document ConcurrentQueue and de-inline its implementation
ConcurrentQueue is currently used only by two classes and a test, but
modifying concurrent_queue.h requires recompiling 30 source files. None
of the member functions is so lightweight as to make it worth inlining.

An alternative to `@note ConcurrentQueue is unable to execute jobs if
@p threadCount == 0.` is `assert(threadCount != 0);`. But this would
force classes that contain a ConcurrentQueue data member to always start
a thread, even if they detect at runtime that they are never going to
enqueue a job.

Add Job type alias to avoid repeating the type.

Use default member initializers instead of the member initializer list
to make it clear [to the reader of the header] that no data member is
left uninitialized.
2021-12-29 09:36:44 +01:00
Igor Kushnir
c333fbc7d0 ConcurrentQueueTest::randomCalls(): test dominant enqueue()
Add another data column to randomCalls() - boostEnqueueOperationWeight -
that determines whether or not enqueue() operation's weight/probability
is much greater than the other operations' weights. The new column
allows to retain the existing much-closer-to-equal weights, which test
other aspects of ConcurrentQueue and have detected bugs already.

Reduce the number of thread count data rows to offset the test duration
increase somewhat.
2021-12-29 09:36:44 +01:00
Igor Kushnir
b514ba1270 tests: add ConcurrentQueueTest::randomCalls()
The new test is a randomized stress test. It consistently passes right
now. The test's detailed output can be analyzed to reveal anomalies and
bugs. The test can catch various bugs that future changes to
ConcurrentQueue's code may introduce.
2021-12-29 09:36:44 +01:00
Igor Kushnir
2cbcaaa391 tests: add ConcurrentQueueTest::waitAllFromMultipleThreads()
This new test hangs because ConcurrentQueue::nextJob() unblocks only
one of the threads that wait for _waitVar.
2021-12-29 09:36:44 +01:00
Igor Kushnir
34b0698d02 Make ConcurrentQueueTest::cancelPending1UserThread() non-flaky
ConcurrentQueueTest::cancelPending1UserThread() often fails when
ConcurrentQueueTest is launched from Qt Creator immediately after
switching between Debug and Release YACReader build configurations.
The CPU busyness must be affecting the thread scheduling timing, which
breaks the test's timing assumptions in this case.

Use the return value of ConcurrentQueue::cancelPending() instead of
relying on the timing of thread scheduling to determine the number of
canceled jobs.
2021-12-29 09:36:44 +01:00
Igor Kushnir
4bbd16c3b3 tests: add ConcurrentQueueTest::cancelPending1UserThread()
This new test consistently fails because of a bug in
ConcurrentQueue::cancelPending() described in the following comment:
https://github.com/YACReader/yacreader/issues/201#issuecomment-774987383
2021-12-29 09:36:44 +01:00
Igor Kushnir
ec938651c4 tests: add the first Qt Test - ConcurrentQueueTest
Place common Qt Test qmake code into tests/qt_test.pri.

Build tests as part of top-level YACReader project unless no_tests
CONFIG option is set. This way the tests are built by default during
development. Packagers can skip building tests by running
`qmake "CONFIG+=no_tests"`.

Both ConcurrentQueueTest::singleUserThread() and
ConcurrentQueueTest::multipleUserThreads() pass. Evidently
ConcurrentQueue::enqueue() can be safely called from multiple threads on
the same ConcurrentQueue object with no additional synchronization. Once
each thread enqueues all its jobs, one thread can safely call waitAll().
2021-12-29 09:36:44 +01:00