Difference between revisions of "Thread"
(reorder functions by name) |
|||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
− | The ''Threads'' plugin provides the ability to run Lua code in separate threads, taking advantage of multiple cores where available. | + | The '''Threads''' plugin provides the ability to run Lua code in separate threads, taking advantage of multiple cores where available. |
+ | |||
+ | To add the '''Threads''' plugin to your application you call: | ||
+ | <source lang="lua"> | ||
+ | require "Threads" | ||
+ | </source> | ||
=== Example === | === Example === | ||
Line 19: | Line 24: | ||
local ok = false | local ok = false | ||
while not ok do ok = thread:getResult() end | while not ok do ok = thread:getResult() end | ||
− | print(" | + | print("end") |
</source> | </source> | ||
Revision as of 18:14, 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.
To add the Threads plugin to your application you call:
require "Threads"
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("end")
MethodsThread.new creates a new thread object Thread:execute starts/executes the thread |
EventsConstants |