리소스 로딩... 로딩...

잠금

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/Thread Thread}, {@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/threading/eventLoop}, {@fun/Threads/threads/threads/eventLoop}

현재 스레드 조건