Dict()
函数用于创建一个字典对象,用于在并发线程间传递数据。
Dict()
函数返回一个ThreadDict
对象。
ThreadDict
对象
Dict()
”`javascript function threadFun1(obj) { obj[“age”] = 100 while (true) { Log(“threadFun1 obj:”, obj) Sleep(5000) } }
function threadFun2(obj) { while (true) { Log(“threadFun2 obj:”, obj) Sleep(5000) } }
function main() {
var obj = {“age”: 10}
var t1 = threading.Thread(threadFun1, obj)
var t2 = threading.Thread(threadFun2, obj)
t1.join()
t2.join()
}
向并发线程执行函数传入普通对象,测试修改对象键值后是否会影响其他线程中的对象键值。
javascript
function threadFun1(threadDict) {
threadDict.set(“age”, 100)
while (true) {
Log(threadFun1 threadDict.get("age"):
, threadDict.get(“age”))
Sleep(5000)
}
}
function threadFun2(threadDict) {
while (true) {
Log(threadFun2 threadDict.get("age"):
, threadDict.get(“age”))
Sleep(5000)
}
}
function main() { var threadDict = threading.Dict() threadDict.set(“age”, 10) var t1 = threading.Thread(threadFun1, threadDict) var t2 = threading.Thread(threadFun2, threadDict)
t1.join()
t2.join()
}
向并发线程执行函数传入
Dict()函数创建的
ThreadDict”`对象,测试修改对象键值后是否会影响其他线程中的对象键值。
向并发线程函数传入普通对象时采用深拷贝方式传递,在并发线程中修改键值不会影响其他线程中的字典。 支持回测系统、实盘环境。
{@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/Event Event}, {@fun/Threads/threading/Thread Thread}, {@fun/Threads/threading/pending pending}, {@fun/Threads/threading/eventLoop eventLoop}