On Saturday 14 November 2015 14:19:18 David Faure wrote: > indeed. > > > This code: > > > qCDebug(SYCOCA) << "checking file timestamps"; > > > const QDateTime stamp = QDateTime::fromMSecsSinceEpoch(timestamp); > > > > You're using the function that creates a LocalTime timestamp and yet: > QDateTime::fromMSecsSinceEpoch() indeed creates a localtime timestamp, > which means it calls qt_localtime() which calls tzset(), so it's not > threadsafe. > > #1 0x00007ffff7118d1f in qt_tzset () at tools/qdatetime.cpp:2117 > #2 0x00007ffff7119194 in qt_localtime (msecsSinceEpoch=1447506886000, > localDate=0x7fffffffbed0, localTime=0x7fffffffbec0, > daylightStatus=0x7fffffffbebc) at tools/qdatetime.cpp:2 333
We can easily add a mutex around this. An uncontended mutex on Linux is very, very fast. It might cause some false sharing and cache thrashing, but it shouldn't be too noticeable. > Yeah, I'm 100% sure most code out there doesn't convert to localtime, > hence my suggestion of QFileInfo::lastModifiedUtc(), to avoid breaking code. > > But then we also need QDateTime::fromMSecsSinceEpoch(time_t, UTC) ? Yeah... Another way, a little more difficult, would be to be lazy: keep the UTC date and wait for the user to decide which timezone to use. The problem with lazy is that QDateTime is shared and I removed the laziness in 5.5 due to threading problems. It's possible to do it if we do it right: we'd have to make sure we always write to the same members and in the same order. We'd need some atomics. > Is there really no way to do localtime/UTC conversions in a threadsafe way? The problem is finding out what timezone it is in the first place. We have QTimeZone and we could read the system file, bypassing localtime_r and tzset. John would know more. > This tzset() issue is really awful, we'll never manage to make sure that > 100% of the code that needs to be threadsafe uses UTC everywhere. Hence the mutex. -- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Software Architect - Intel Open Source Technology Center PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358