ThreadDict
Thread-safe dictionary object for data sharing in multi-threaded environments.
get
The get() function is used to retrieve the value of a key recorded in a dictionary object.
get(key)Examples
Use event objects to notify threads to read and modify data.
javascript
function main() {
var event = threading.Event()
var dict = threading.Dict()
dict.set("data", 100)
var t1 = threading.Thread(function(dict, event) {
Log(`thread1, dict.get("data"):`, dict.get("data"))
event.set()
event.clear()
event.wait()
Log(`after main change data, thread1 dict.get("data"):`, dict.get("data"))
dict.set("data", 0)
}, dict, event)
event.wait()
dict.set("data", 99)
event.set()
event.clear()
t1.join()
Log(`main thread, dict.get("data"):`, dict.get("data"))
}Returns
| Type | Description |
string / number / bool / object / array / any (any type supported by the platform) | The |
Arguments
| Name | Type | Required | Description |
key | string | Yes | The |
See Also
set
The set() function is used to set key-value pairs.
set(key, value)Examples
Supports passing functions as key values.
javascript
function main() {
var dict1 = threading.Dict()
dict1.set("func1", function(p) {
Log("func1 p:", p)
})
threading.Thread(function(dict1) {
var func1 = dict1.get("func1")
func1("test")
}, dict1).join()
}Arguments
| Name | Type | Required | Description |
key | string | Yes | The |
value | string / number / bool / object / array / function / any (any type supported by the platform) | Yes | The |
See Also