Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.15.2
-
None
-
-
21
-
d0ae1ef33a6eed02acde7304298794f4f0119e16 (qt/qtbase/dev) 93345662b05359e0b895faf2be0f2358af08339b (qt/qtbase/6.2)
-
Qt6_Foundation_Sprint 38, Qt6_Foundation_Sprint 39
Description
The following code reproduces the assert (in debug mode) and the following crash. Tested on Windows with msvc (5.15.2\msvc2019_64). I've also found a workaround, which might hint at the nature of the problem.
If this is unavoidable behavior then I suggest it should be documented, but I hope that a transparent fix can be worked out in the implementation itself to gracefully handle multi-threaded access.
#include <QDateTime> #include <atomic> #include <thread> static std::atomic_bool g_startThreads = false; static void thread_func() { for (; !g_startThreads; ); const auto date = QDateTime::currentDateTimeUtc(); date.toString("yyyyMMdd_hhmmss"); } int main(int, char*[]) { std::vector<std::thread> threads; for (int i = 0; i < 2; ++i) threads.emplace_back(&thread_func); // The following line fixes the problem (presumably, by performing orderly first initialization of the internal Qt structures used for QDateTime::toString() //QDateTime::currentDateTimeUtc().toString("yyyyMMdd_hhmmss"); g_startThreads = true; for (auto& th: threads) th.join(); return 0; }
Here's the assertion triggered by this demo:
Program: E:\Development\Tools\Qt\5.15.2\msvc2019_64\bin\Qt5Cored.dll Module: 5.15.2 File: time\qcalendar.cpp Line: 105 ASSERT: "byId[size_t(id)] == nullptr" in file time\qcalendar.cpp, line 105
Attachments
Issue Links
- relates to
-
QTBUG-84575 QCalendar class is not reentrant
-
- Closed
-
For Gerrit Dashboard: QTBUG-93004 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
360683,26 | QCalendar: Thread-safe calendar backend registration | dev | qt/qtbase | Status: MERGED | +2 | 0 |
363602,2 | QCalendar: Thread-safe calendar backend registration | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |
363749,3 | QCalendarRegistry: Explicitly disable moving and copying | dev | qt/qtbase | Status: MERGED | +2 | 0 |
364041,2 | QCalendarRegistry: Explicitly disable moving and copying | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |