Re: [閒聊] 各種神人的code
※ 引述《saxontai (黑暗,點綴孤零零的星)》之銘言:
: 看到同事寫的 calibration tool (Qt-based & multithreading)
: 程式碼中有以下這段:
: ClearMutex.lock(); // 鎖住
: wait.wait(&ClearMutex); // 等解鎖
: ClearMutex.unlock(); // 解鎖
: 我能說啥呢? (煙)
這段是正確的
wait.wait(&ClearMutex) 會把ClearMutext解開,然後等待被喚醒
(http://qt-project.org/doc/qt-4.8/qwaitcondition.html#wait)
喚醒後會重新鎖上ClearMutext所以和ClearMutext.unlock()中間可以做一些事情
wait.wait(&ClearMutext);
...
ClearMutext.unlock();
不過也有例子是不做事,只是單純的需要wait
比方說:http://qt-project.org/doc/qt-4.8/threads-waitconditions.html
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.129.12.207
※ 文章網址: http://www.ptt.cc/bbs/Soft_Job/M.1411405431.A.64D.html
推
09/23 02:12, , 1F
09/23 02:12, 1F
→
09/23 02:12, , 2F
09/23 02:12, 2F
→
09/23 17:07, , 3F
09/23 17:07, 3F
討論串 (同標題文章)
Soft_Job 近期熱門文章
PTT職涯區 即時熱門文章