Difference between revisions of "Thread"
m (Text replacement - "<source" to "<syntaxhighlight") |
|||
Line 8: | Line 8: | ||
To add the '''Threads''' plugin to your application you call: | To add the '''Threads''' plugin to your application you call: | ||
− | < | + | <syntaxhighlight lang="lua"> |
require "Threads" | require "Threads" | ||
</source> | </source> | ||
Line 14: | Line 14: | ||
=== Example === | === Example === | ||
'''Simple example of getting result from a thread''' | '''Simple example of getting result from a thread''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
require "Threads" | require "Threads" | ||
local thread = Thread.new() | local thread = Thread.new() |
Revision as of 14:31, 13 July 2023
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: <syntaxhighlight lang="lua"> require "Threads" </source>
Example
Simple example of getting result from a thread <syntaxhighlight lang="lua"> 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") </source>
MethodsThread.new creates a new thread object Thread:execute starts/executes the thread |
EventsConstants |