Difference between revisions of "X Threads"

From GiderosMobile
(→‎Description: fixed attempt to perform arithmetic on local 'a' (a nil value))
Line 13: Line 13:
 
local thread = Thread.new()
 
local thread = Thread.new()
 
thread:setFunction(function()
 
thread:setFunction(function()
   local a
+
   local a = 0
 
   for i = 1, 10000000 do
 
   for i = 1, 10000000 do
 
     a += 1
 
     a += 1

Revision as of 06:01, 24 May 2019


Supported platforms: Platform android.pngPlatform ios.pngPlatform pc.pngPlatform mac.pngPlatform winrt.pngPlatform win32.png
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!")

Class

Thread