输入/搜索内容
内置函数
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
threading.Thread
threading.getThread
threading.mainThread
threading.currentThread
threading.Lock
threading.Condition
threading.Event
threading.Dict
threading.Serve
threading.pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
结构体
内置变量与常量
通用约定
交易所

创建线程锁对象。

Lock()

示例

两个并发线程访问共享资源。

javascript
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() }

返回值

类型描述

ThreadLock对象

线程锁对象。

参考

备注

支持回测系统、实盘环境。