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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.15.1
    • Core: Date/Time
    • 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

          For Gerrit Dashboard: QTBUG-88815
          # Subject Branch Project Status CR V

          Activity

            People

              Eddy Edward Welbourne
              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