Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-88815

QDate::FromString breaks when accessed from multiple threads using default calendar parameter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 5.15.1
    • Fix Version/s: None
    • Component/s: Core: Date/Time
    • Labels:
      None

      Description

      After updating from Qt 5.12.9 to 5.15.1, part of our multithreaded code which accesses QDate::FromString started firing a Q_ASSERT in qcalendar.cpp non determinstically, line 103.  After debugging into Qt source code, the problem is with the global static calendar registry:

      Q_GLOBAL_STATIC(Registry, calendarRegistry);

      This registry is accessed concurrently when QDate::FromString is called, and the assert  Q_ASSERT(byId[size_t(id)] == nullptr)  fails whenever QDate::FromString is called using default calendar parameter which makes sense, since there is already a gregorian default calendar in registry.

      Sample code to reproduce:

       
      class HelloWorldTask : public QRunnable
      {
      	void run() override
      	{
      		QDate::fromString("2017-12-21", "yyyy-MM-dd");
      	}
      };
      
      for(int i = 0; i < 40 ; ++i)
      {
      	HelloWorldTask *hello = new HelloWorldTask();
      	QThreadPool::globalInstance()->start(hello);
      }
      QThreadPool::globalInstance()->waitForDone();
      

       

      We worked around the problem using a constant global static QCalendar object which is passed as the last parameter in QDate::FromString

       

      Thanks

       

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              Eddy Edward Welbourne
              Reporter:
              ruediger Matthias Fischbeck
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes