Difference between revisions of "Thread"
(removed language stuff) |
(reorder functions by name) |
||
Line 26: | Line 26: | ||
=== Methods === | === Methods === | ||
[[Thread.new]] ''creates a new thread object''<br/><!--GIDEROSMTD:Thread.new() creates a new thread object--> | [[Thread.new]] ''creates a new thread object''<br/><!--GIDEROSMTD:Thread.new() creates a new thread object--> | ||
− | + | ||
− | [[Thread:execute]] ''starts/executes | + | [[Thread:execute]] ''starts/executes the thread''<br/><!--GIDEROSMTD:Thread:execute(vararg) starts/executes the thread--> |
− | [[Thread: | + | [[Thread:fetchData]] ''returns any data sent by thread sendData call''<br/><!--GIDEROSMTD:Thread:fetchData() returns any data sent by thread sendData call--> |
− | |||
− | |||
[[Thread:getNumLogicalCores]] ''returns number of logical cores on host machine''<br/><!--GIDEROSMTD:Thread:getNumLogicalCores() returns number of logical cores on host machine--> | [[Thread:getNumLogicalCores]] ''returns number of logical cores on host machine''<br/><!--GIDEROSMTD:Thread:getNumLogicalCores() returns number of logical cores on host machine--> | ||
+ | [[Thread:getResults]] ''gets any results from thread''<br/><!--GIDEROSMTD:Thread:getResults(wait_time) gets any results from thread--> | ||
[[Thread:requestTermination]] ''sets a flag to terminate thread''<br/><!--GIDEROSMTD:Thread:requestTermination() sets a flag to terminate thread--> | [[Thread:requestTermination]] ''sets a flag to terminate thread''<br/><!--GIDEROSMTD:Thread:requestTermination() sets a flag to terminate thread--> | ||
+ | [[Thread:resume]] ''resumes a thread that has been yielded''<br/><!--GIDEROSMTD:Thread:resume(...) resumes a thread that has been yielded--> | ||
[[Thread.sendData]] ''sends data for retrieval by main thread (only valid inside thread function)''<br/><!--GIDEROSMTD:Thread.sendData(...) sends data for retrieval by main thread (only valid inside thread function)--> | [[Thread.sendData]] ''sends data for retrieval by main thread (only valid inside thread function)''<br/><!--GIDEROSMTD:Thread.sendData(...) sends data for retrieval by main thread (only valid inside thread function)--> | ||
− | [[Thread: | + | [[Thread:setFunction]] ''sets Lua function that thread will execute''<br/><!--GIDEROSMTD:Thread:setFunction(func) sets Lua function that thread will execute--> |
− | [[Thread | + | [[Thread:status]] ''returns current status of the thread''<br/><!--GIDEROSMTD:Thread:status() returns current status of the thread--> |
+ | [[Thread.yield]] ''pauses executions of thread (only valid inside thread function)''<br/><!--GIDEROSMTD:Thread.yield(...) pauses executions of thread (only valid inside thread function)--> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| |
Revision as of 18:05, 25 April 2021
Supported platforms:
Available since: 2018.10
Description
The Threads plugin provides the ability to run Lua code in separate threads, taking advantage of multiple cores where available.
Example
Simple example of getting result from thread
require "Threads"
local thread = Thread.new()
thread:setFunction(function()
local a = 0
for i = 1, 10000000 do a += 1 end
return i
end)
thread:execute()
local ok = false
while not ok do ok = thread:getResult() end
print("woot!")
MethodsThread.new creates a new thread object Thread:execute starts/executes the thread |
EventsConstants |