Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QThread & QMutex



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


  • Lifetime Qt Champion

    Hi,

    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 ?

    Hi;

    tryLock always returns true.

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


  • @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