Difference between revisions of "Thread"

From GiderosMobile
(merged the threads plugin with the thread class)
Line 59: Line 59:
  
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Revision as of 16:29, 30 January 2020


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!")

Methods

Thread.new Creates a new thread object.
Thread:setFunction Sets Lua function that thread will execute.
Thread:execute Starts/executes our thread
Thread:resume Resumes a thread that has been yielded.
Thread.yield Pauses executions of thread (only a valid call inside thread function).
Thread:status Returns current status of the thread.
Thread:getNumLogicalCores Returns number of logical cores on host machine.
Thread:requestTermination Sets a flag to terminate thread.
Thread.sendData Sends data for retrieval by main thread (only a valid call inside thread function).
Thread:fetchData Returns any data sent by thread sendData call.
Thread:getResults Get any results from thread.

Events

Constants