について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()
}
2つの同時スレッドが共通のリソースにアクセスします.
バックテストシステムとライブ取引環境をサポートします
{@fun/Threads/threading/getThread getThread}, {@fun/Threads/threading/mainThread mainThread}, {@fun/Threads/threading/currentThread currentThread}, {@fun/Threads/threads/threading/Thread Thread}, {@fun/Threads/threads/threading/condition Condition}, {@fun/Threads/threads/threading/event Event}, {@fun/Threads/threads/threading/mainThread mainThread}, {@fun/Threads/threads/threading/currentThread currentThread}, {@fun/Threads/threads/threading/threads/threading/threadThreadThread}, {@fun/Threads/threads/threads/threads/threads/eventLoopイベント}, {@fun/Threads/threads/threads/thre
currentスレッド 条件