資源の読み込みに... 荷物...

ThreadCondition について

条件オブジェクト,マルチスレッド同期に使用されます.

通知する

についてnotify()呼び出したスレッドのみです.wait()方法が目覚めるでしょう

通知する

function consumer(dict, condition) {
    while (true) {
        condition.acquire()
        while (dict.get("array").length == 0) {
            Log(threading.currentThread().name(), "wait()...", ", array:", dict.get("array"))
            condition.wait()
        }
        var arr = dict.get("array")
        var num = arr.shift()
        Log(threading.currentThread().name(), ", num:", num, ", array:", arr, "#FF0000")
        dict.set("array", arr)
        Sleep(1000)
        condition.release()
    }
}

function main() {
    var condition = threading.Condition()
    var dict = threading.Dict()
    dict.set("array", [])
    var t1 = threading.Thread(consumer, dict, condition)
    var t2 = threading.Thread(consumer, dict, condition)
    var t3 = threading.Thread(consumer, dict, condition)
    Sleep(1000)
    var i = 0
    while (true) {
        condition.acquire()
        var msg = ""
        var arr = dict.get("array")
        var randomNum = Math.floor(Math.random() * 5) + 1
        if (arr.length >= 3) {
            condition.notifyAll()
            msg = "notifyAll"
        } else {
            arr.push(i)
            dict.set("array", arr)
            if (randomNum > 3 && arr.length > 0) {
                condition.notify()
                msg = "notify"
            } else {
                msg = "pass"
            }
            i++
        }

        Log(_D(), "randomNum:", randomNum, ", array:", arr, ", msg:", msg)
        condition.release()
        Sleep(1000)
    }
}

試しにnotify()待機糸を目覚めさせる機能です

についてnotify()待機列のスレッドを起こします

その時にnotify()糸がスレッドロックに戻ります

{@fun/Threads/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/wait wait}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/ThreadCondition/threadCondition/wait wait}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/threads/threadCondition/release release}, {@fun/threads/threadCondition/release release release}, {@fun/threads/threadCondition/release release

全員に知らせる

についてnotifyAll()待機するスレッドをすべて起こします.

全員に知らせる

参照してくださいThreadCondition.notify()例のセクションです

についてnotifyAll()起き上がったスレッドがスレッドロックを再獲得します 起き上がったスレッドがスレッドロックを再獲得します

{@fun/Threads/ThreadCondition/notify notify}, {@fun/Threads/ThreadCondition/wait wait}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/thread release}, {@fun/threads/threadCondition/thread release release}, {@fun/threads/threadCondition/thread release release}, {@fun/threads/threadCondition/thread release release}, {@fun/threads/threadCondition/thread release release release}, {@fun/threads/threadCondition/thread release release release release}, {@fun/threads/threadCondition/thread

待って

についてwait()特定の設計条件下でスレッドを待機させる機能です

待って

参照してくださいThreadCondition.notify()例のセクションです

についてwait()機能はスレッドロックを解放し,目覚めるとスレッドロックを再獲得します.

{@fun/Threads/ThreadCondition/notify notify}, {@fun/Threads/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/Threads/ThreadCondition/release release}, {@fun/ThreadCondition/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/Threads/ThreadCondition/release release}, {@fun/Threads/ThreadCondition/release release}, {@fun/threads/threadCondition/release release}, {@fun/threads/threadCondition/release release release}, {@fun/threads

獲得する

についてacquire()機能はスレッドロック (ロック) を要求するために使用されます.

取得する

参照してくださいThreadCondition.notify()例のセクションです

使用前wait()ロープのロック (ロック) を要求する必要があります.

{@fun/Threads/ThreadCondition/notify notify}, {@fun/Threads/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/wait wait}, {@fun/ThreadCondition/ThreadCondition/release release}, {@fun/ThreadCondition/ThreadCondition/release release}, {@fun/ThreadCondition/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/wait wait}, {@fun/Threads/ThreadCondition/release release}, {@fun/ThreadCondition/threadCondition/release release}, {@fun/threadCondition/threadCondition/release release}, {@threadCondition/threadCondition/release release release}, {@fun/threadCondition/threadCondition/release release release}, {@fun/thread

解放する

についてrelease()機能はスレッドロックを解き放つために使われます.

解放する

参照してくださいThreadCondition.notify()例のセクションです

使用後wait()ロープを解き放つ必要があります. ロープを解き放つ必要があります.

{@fun/Threads/ThreadCondition/notify notify}, {@fun/Threads/ThreadCondition/notifyAll notifyAll}, {@fun/Threads/ThreadCondition/wait wait}, {@fun/Threads/ThreadCondition/acquire acquire}, {@fun/ThreadCondition/threadCondition/acquire acquire}, {@fun/ThreadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition}, {@fun/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/threadCondition/acquire

ThreadEvent について ThreadDict について