<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # QWaitCondition Class Reference ## [[QtCore](index.htm) module] 該QWaitCondition類提供了線程同步的條件變量。[More...](#details) ### Methods * `__init__ (self)` * `bool wait (self, QMutex?mutex, int?msecs?=?ULONG_MAX)` * `bool wait (self, QReadWriteLock?readWriteLock, int?msecs?=?ULONG_MAX)` * `wakeAll (self)` * `wakeOne (self)` * * * ## Detailed Description 該QWaitCondition類提供了線程同步的條件變量。 QWaitCondition允許一個線程告訴某種條件已經滿足其他線程。一個或多個線程可以阻塞等待QWaitCondition設置的條件與[wakeOne](qwaitcondition.html#wakeOne)()或[wakeAll](qwaitcondition.html#wakeAll)( ) 。使用[wakeOne](qwaitcondition.html#wakeOne)( )來喚醒中隨機選擇的條件或[wakeAll](qwaitcondition.html#wakeAll)( )來喚醒他們。 例如,讓我們假設我們有每當用戶按下一個鍵應該執行三項任務。每個任務可以被分成一個線程,每一個都具有一[run()](qthread.html#run)身體是這樣的: ``` forever { mutex.lock(); keyPressed.wait(&mutex); do_something(); mutex.unlock(); } ``` 這里,本`keyPressed`變量的類型QWaitCondition的全局變量。 第四個線程將讀取按鍵和每收到一個,比如這個時候喚醒其它三個線程了: ``` forever { getchar(); keyPressed.wakeAll(); } ``` 其中三個線程被喚醒的順序是不確定的。此外,如果某些線程仍在`do_something()`當按鍵被按下時,他們不會被喚醒(因為他們沒有等待條件變量) ,所以該任務將不會為該按鍵來執行。這個問題可以用一個計數器和一個可以解決[QMutex](qmutex.html)守護它。例如,這里的工作線程新的代碼: ``` forever { mutex.lock(); keyPressed.wait(&mutex); ++count; mutex.unlock(); do_something(); mutex.lock(); --count; mutex.unlock(); } ``` 下面是第四個線程的代碼: ``` forever { getchar(); mutex.lock(); // Sleep until there are no busy worker threads while (count > 0) { mutex.unlock(); sleep(1); mutex.lock(); } keyPressed.wakeAll(); mutex.unlock(); } ``` 互斥鎖是必要的,因為兩個線程試圖改變同一個變量的值的結果同時是不可預知的。 等待條件是一個強大的線程同步原語。該[Wait Conditions](index.htm)示例顯示了如何使用QWaitCondition作為替代[QSemaphore](qsemaphore.html)用于控制訪問環形緩沖器由一個生產者線程和消費者線程共享。 * * * ## Method Documentation ``` QWaitCondition.__init__ (self) ``` 構造一個新的等待條件的對象。 ``` bool QWaitCondition.wait (self, QMutex?mutex, int?msecs?=?ULONG_MAX) ``` 釋放鎖定_mutex_并等待在等待條件。該_mutex_必須首先鎖定調用線程。如果_mutex_是不是在鎖定狀態,該函數將立即返回。如果_mutex_是一個遞歸互斥體,該函數立即返回。該_mutex_將被解鎖,并且調用線程將被阻塞,直到下列任一條件滿足: * Another thread signals it using [wakeOne](qwaitcondition.html#wakeOne)() or [wakeAll](qwaitcondition.html#wakeAll)(). This function will return true in this case. * _time_ milliseconds has elapsed. If _time_ is `ULONG_MAX` (the default), then the wait will never timeout (the event must be signalled). This function will return false if the wait timed out. 互斥將被返回到相同的鎖定狀態。這個功能被提供,以允許從鎖定狀態到等待狀態的原子躍遷。 **See also** [wakeOne](qwaitcondition.html#wakeOne)()和[wakeAll](qwaitcondition.html#wakeAll)( ) 。 ``` bool QWaitCondition.wait (self, QReadWriteLock?readWriteLock, int?msecs?=?ULONG_MAX) ``` 釋放鎖定_readWriteLock_并等待在等待條件。該_readWriteLock_必須首先鎖定調用線程。如果_readWriteLock_是不是在鎖定狀態,該函數將立即返回。該_readWriteLock_不能被遞歸鎖定,否則此功能將無法正常釋放該鎖。該_readWriteLock_將被解鎖,并且調用線程將被阻塞,直到下列任一條件滿足: * Another thread signals it using [wakeOne](qwaitcondition.html#wakeOne)() or [wakeAll](qwaitcondition.html#wakeAll)(). This function will return true in this case. * _time_ milliseconds has elapsed. If _time_ is `ULONG_MAX` (the default), then the wait will never timeout (the event must be signalled). This function will return false if the wait timed out. 該_readWriteLock_將返回到相同的鎖定狀態。這個功能被提供,以允許從鎖定狀態到等待狀態的原子躍遷。 此功能被引入Qt的4.4 。 **See also** [wakeOne](qwaitcondition.html#wakeOne)()和[wakeAll](qwaitcondition.html#wakeAll)( ) 。 ``` QWaitCondition.wakeAll (self) ``` 喚醒等待等待條件的所有線程。在該線程被喚醒的順序依賴于操作系統的調度策略,并不能被控制或預測。 **See also** [wakeOne](qwaitcondition.html#wakeOne)( ) 。 ``` QWaitCondition.wakeOne (self) ``` 喚醒等待的一個線程等待條件。該被喚醒的線程依賴于操作系統的調度策略,并且不能被控制或預測。 如果你想喚醒一個特定的線程,該解決方案通常使用不同的等待狀態,并有不同的線程在等待不同的條件。 **See also** [wakeAll](qwaitcondition.html#wakeAll)( ) 。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看