Important: Please read the Qt Code of Conduct -

QThread & QMutex

  • How do you know that the thread has already mutexed ? QThread::isRunning is not answer...

  • Lifetime Qt Champion


    You can use tryLock for example.

    Out of curiosity, what is your use case ?

  • @SGaist said in QThread & QMutex:

    Out of curiosity, what is your use case ?


    tryLock always returns true.

    	// RSM is own object (Remote Service Manager.  It likes OO-RPC (and likes Qt Remote Object).
    		id	: chRSM
    		id			: chTestx
    		chRSM		: chRSM
    		id		: chLoaderPage
    		source	: "rsmfile:///Content/ChPageTest.ui.qml"
    		// if true, everthing ok !!!
    		//asynchronous: true
    			item.chRSM = chRSM;
    QNetworkAccessManager* CChQMLRSMNetworkAccessManagerFactory::create(
    	QObject*	ChParent)
    	// dead lock occurs here, cause'f m_ChQMLRSM is in main thread and locked !

  • @VeNToR said in QThread & QMutex:

    ck always returns true.

    Hi @VeNToR!

    By chance is your mutex created using QMutex::Recursive and are you using tryLock in the same thread?

    from QMutex documentation:
    "Calling this function multiple times on the same mutex from the same thread is allowed if this mutex is a recursive mutex. If this mutex is a non-recursive mutex, this function will always return false when attempting to lock the mutex recursively."

Log in to reply