..Lock()
फ़ंक्शन का उपयोग थ्रेड लॉक ऑब्जेक्ट बनाने के लिए किया जाता है.
..Lock()
फ़ंक्शन एक थ्रेड लॉक ऑब्जेक्ट लौटाता है.
ThreadLock
वस्तु
तालाबंदी
function consumer(productionQuantity, dict, lock) {
for (var i = 0; i < productionQuantity; i++) {
lock.acquire()
var count = dict.get("count")
Log("consumer:", count)
Sleep(1000)
lock.release()
}
}
function producer(productionQuantity, dict, lock) {
for (var i = 0; i < productionQuantity; i++) {
lock.acquire()
dict.set("count", i)
Log("producer:", i)
Sleep(1000)
lock.release()
}
}
function main() {
var dict = threading.Dict()
dict.set("count", -1)
var lock = threading.Lock()
var productionQuantity = 10
var producerThread = threading.Thread(producer, productionQuantity, dict, lock)
var consumerThread = threading.Thread(consumer, productionQuantity, dict, lock)
consumerThread.join()
producerThread.join()
}
दो समवर्ती थ्रेड एक आम संसाधन तक पहुँचते हैं.
यह बैकटेस्टिंग प्रणाली और लाइव ट्रेडिंग वातावरण का समर्थन करता है।
{@fun/Threads/threading/getThread getThread}, {@fun/Threads/threading/mainThread mainThread}, {@fun/Threads/threading/currentThread currentThread}, {@fun/Threads/threads/threading/ThreadThread}, {@fun/Threads/threads/threading/Condition Condition}, {@fun/Threads/threads/threading/Event Event}, {@fun/Threads/threads/threading/Dict Dict}, {@fun/Threads/threads/threading/pending pending}, {@fun/Threads/threads/threading/eventLoop}
वर्तमान थ्रेड स्थिति