The getData()
function is used to access variables recorded in the thread environment. The data is valid when the thread has not executed the join()
function (waiting for exit success) and has not executed the terminate()
function (terminating the thread forcibly).
The getData()
function returns the key value corresponding to the key
parameter in the key-value pair stored in the current thread context.
string, number, bool, object, array, null value and other types supported by the system
getData() getData(key)
The key
parameter is the key name of the stored key-value pair.
key true string
function main() {
var t1 = threading.Thread(function() {
for (var i = 0; i < 5; i++) {
threading.currentThread().setData("count", i)
Log(`setData("count"):`, i)
Sleep(1000)
}
})
for (var i = 0; i < 5; i++) {
var count = threading.getThread(t1.id()).getData("count")
Log(`getData("count"):`, count)
Sleep(1000)
}
t1.join()
}
Record the value of the key count
in the concurrent thread environment, and then read the key value of count
in the main thread.
{@fun/Threads/Thread/peekMessage peekMessage}, {@fun/Threads/Thread/postMessage postMessage}, {@fun/Threads/Thread/join join}, {@fun/Threads/Thread/terminate terminate}, {@fun/Threads/Thread/setData setData}, {@fun/Threads/Thread/id id}, {@fun/Threads/Thread/name name}, {@fun/Threads/Thread/eventLoop eventLoop}
terminate setData