```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()
}
Fungsi pelaksanaan untuk sebuah thread yang bersamaan diteruskan ke objek biasa, dan diuji apakah perubahan nilai kunci dari objek tersebut menyebabkan perubahan nilai kunci objek di thread lain.
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()
}
Mengirimkan fungsi eksekusi ke thread paralelDict()
Fungsi yang dibuatThreadDict
Object, untuk menguji apakah perubahan nilai kunci objek akan menyebabkan perubahan nilai kunci objek pada thread lain.
Fungsi simultan thread diteruskan ke deep copy saat mengirim objek biasa, mengubah nilai kunci pada thread simultan tanpa mempengaruhi dictionary pada thread lain.
Mendukung sistem retargeting, lingkungan real-time.
{@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/threading/Thread Thread}, {@fun/Threads/threading/threading/pending pending}, {@fun/Threads/threading/eventLoop}
Peristiwa sedang menunggu