我只是想執行下面的代碼。QMutex,如果線程在運行,請在此等待
QString Class1::getNonce()
{
//if some thread is getting nonce wait here until it finishes the its own job.
mutex.lock();
QString nonce=QString("%1").arg(QDateTime::currentDateTime().toTime_t());
mutex.unlock();
return nonce;
}
即使我用互斥鎖寫不同的線程得到相同的現時。我怎麼解決這個問題? 謝謝。
是互斥的靜態?或者你只使用Class1的一次實例? – drescherjm
是的,它是在Class1中作爲QMutex互斥體;而我只是使用互斥這個功能。 –
也許是因爲'QDateTime :: currentDateTime'只有毫秒分辨率? –