Thread

From GiderosMobile
Revision as of 21:05, 15 April 2021 by MoKaLux (talk | contribs) (removed language stuff)

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 valid 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 valid inside thread function)
Thread:fetchData returns any data sent by thread sendData call
Thread:getResults gets any results from thread

Events

Constants