Difference between revisions of "X Threads"

From GiderosMobile
Line 39: Line 39:
 
[[Special:MyLanguage/Thread:getNumLogicalCores|Thread:getNumLogicalCores]]  ''<translate>Returns number of logical cores on host machine.</translate>''<br/><!-- GIDEROSMTD:Thread:getNumLogicalCores() Returns number of logical cores on host machine. -->
 
[[Special:MyLanguage/Thread:getNumLogicalCores|Thread:getNumLogicalCores]]  ''<translate>Returns number of logical cores on host machine.</translate>''<br/><!-- GIDEROSMTD:Thread:getNumLogicalCores() Returns number of logical cores on host machine. -->
 
[[Special:MyLanguage/Thread:requestTermination|Thread:requestTermination]]  ''<translate>Sets a flag to terminate thread.</translate>''<br/><!-- GIDEROSMTD:Thread:requestTermination() Sets a flag to terminate thread. -->
 
[[Special:MyLanguage/Thread:requestTermination|Thread:requestTermination]]  ''<translate>Sets a flag to terminate thread.</translate>''<br/><!-- GIDEROSMTD:Thread:requestTermination() Sets a flag to terminate thread. -->
[[Special:MyLanguage/Thread:sendData|Thread:sendData]]  ''<translate>Sends data for retrieval by main thread (only a valid call inside thread function).</translate>''<br/><!-- GIDEROSMTD:Thread:sendData() Sends data for retrieval by main thread (only a valid call inside thread function). -->
+
[[Special:MyLanguage/Thread.sendData|Thread.sendData]]  ''<translate>Sends data for retrieval by main thread (only a valid call inside thread function).</translate>''<br/><!-- GIDEROSMTD:Thread.sendData(...) Sends data for retrieval by main thread (only a valid call inside thread function). -->
 
[[Special:MyLanguage/Thread:fetchData|Thread:fetchData]]  ''<translate>Returns any data sent by thread sendData call.</translate>''<br/><!-- GIDEROSMTD:Thread:fetchData() Returns any data sent by thread sendData call. -->
 
[[Special:MyLanguage/Thread:fetchData|Thread:fetchData]]  ''<translate>Returns any data sent by thread sendData call.</translate>''<br/><!-- GIDEROSMTD:Thread:fetchData() Returns any data sent by thread sendData call. -->
 
[[Special:MyLanguage/Thread:getResults|Thread:getResults]]  ''<translate>Get any results from thread.</translate>''<br/><!-- GIDEROSMTD:Thread:getResults(wait_time) Get any results from thread. -->
 
[[Special:MyLanguage/Thread:getResults|Thread:getResults]]  ''<translate>Get any results from thread.</translate>''<br/><!-- GIDEROSMTD:Thread:getResults(wait_time) Get any results from thread. -->

Revision as of 13:39, 4 October 2018


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
  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

none

Constants

none