Hi all

During the QJsonDocument review process, I pointed out a problem with using
const_cast that I argued was a violation of the thread-safety rules. Lars
disagreed, so we talked here at FOSDEM. Strict reading of the docs at
        http://developer.qt.nokia.com/doc/qt-4.8/threads-reentrancy.html
        http://developer.qt.nokia.com/doc/qt-4.8/threads-modules.html#threads-
and-implicitly-shared-classes

say that the implicitly-shared classes are *reentrant*, not thread-safe. That
means no method at all must be called in objects being shared, like global
objects or pointers to objects also used in other threads.

However, in practice, many people have begun relying on an implementation
detail that read-only operations (the const methods) in those classes are
thread-safe. That is, a shared object can be accessed without mutex protection
provided only const functions are called.

That is not codified in the documentation.

I'd like to propose that it is and we say that all const methods in the
implicitly-shared classes are thread-safe. It should also explain that calling
a non-thread-safe method in the same object simultaneously with a thread-safe
one breaks the safety (which is different to what "thread-safety" means to
QCoreApplication::postEvent).

Note that there are a lot of implicitly-shared classes listed at
http://developer.qt.nokia.com/doc/qt-4.8/implicit-sharing.html#shared-classes.

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to