Important: Please read the Qt Code of Conduct -

QMutext ignores errors?

  • Hi,

    I wonder why QMutex ignores any initialization errors from pthread_mutex_init() (or its Windows platform equivalent)?

    If there was any problem, it just prints warning and keeps going, so then the lock() call will be executed on the invalid mutex, won't it?

    Why don't we have any "isOk()" method to check if the initialization went okay?
    For example the QThread.wait() returns bool, which already is enough to indicate a problem (timeout or any other problem). Why not having any information from QMutex?

  • QReadWriteLock has!

  • QMutex and QReadWriteLock are not the same thing and it still doesn't explain why QMutex kind of "ignores" failed initialization.

  • @QMutex kind of “ignores” failed initialization.@

    if you have a look inside qt's mutex src you'll find out it actually does assertions internally

    bq. QMutex and QReadWriteLock are not the same thing

    and so the other ones :) ... the question is which of them is more appropriate and when, which gives better chance for threads synchronization and concurrency?

  • Moderators

    No specific reason, I'd imagine, except that the developers never found a need for it. This is a forum of Qt users, who likely can't comment on design decisions. If you want to ask a Qt engineer directly, you can subscribe to the "Interest mailing list": and ask there.

    Anyway, what is your mutex for? Would you consider a more robust architecture which "doesn't need locks":

Log in to reply