রিসোর্স লোড হচ্ছে... লোডিং...

ঘটনা



```Event()```函数返回一个```ThreadEvent```对象。

```ThreadEvent```对象


Event()

```javascript
function consumer(productionQuantity, dict, pEvent, cEvent) {
    for (var i = 0; i < productionQuantity; i++) {
        while (dict.get("array").length == 0) {
            pEvent.wait()
        }
        if (pEvent.isSet()) {
            pEvent.clear()
        }

        var arr = dict.get("array")
        var count = arr.shift()
        dict.set("array", arr)
        Log("consumer:", count, ", array:", arr)
        cEvent.set()
        Sleep(1000)
    }
}

function producer(productionQuantity, dict, pEvent, cEvent) {
    for (var i = 0; i < productionQuantity; i++) {
        while (dict.get("array").length != 0) {
            cEvent.wait()
        }
        if (cEvent.isSet()) {
            cEvent.clear()
        }

        var arr = dict.get("array")
        arr.push(i)
        dict.set("array", arr)
        Log("producer:", i, ", array:", arr)        
        pEvent.set()       
        Sleep(1000)
    }
}

function main() {    
    var dict = threading.Dict()
    dict.set("array", [])
    var pEvent = threading.Event()
    var cEvent = threading.Event()
    var productionQuantity = 10
    var producerThread = threading.Thread(producer, productionQuantity, dict, pEvent, cEvent)
    var consumerThread = threading.Thread(consumer, productionQuantity, dict, pEvent, cEvent)

    consumerThread.join()
    producerThread.join()
}

দুইটি সমান্তরাল থ্রেড পাবলিক রিসোর্স অ্যাক্সেস করে।

এই অ্যাপ্লিকেশানটি একটি অ্যাক্সেসযোগ্য ডিস্ক সিস্টেম।

{@fun/Threads/threading/getThread getThread}, {@fun/Threads/threading/mainThread mainThread}, {@fun/Threads/threading/currentThread currentThread}, {@fun/Threads/threading/Lock Lock}, {@fun/Threads/threading/Condition Condition}, {@fun/Threads/threading/threading/Thread Thread}, {@fun/Threads/threads/threading/Dict Dict}, {@fun/Threads/threading/pending pending}, {@fun/Threads/threads/threading/eventLoop eventop}, {@fun/Threads/threads/threads/pending pending}, {@fun/Threads/threads/loop eventop}, {@fun/Threads/threads/threads/eventLoop}, {@fun/threads/thre

শর্ত ডিক্ট