Difference between revisions of "X Threads"

From GiderosMobile
(Created page with "__NOTOC__ <languages /> <!-- GIDEROSOBJ:Threads --> '''<translate>Supported platforms</translate>:''' File:Platform android.pngFile:Platform ios.pngFile:Platform pc....")
 
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Threads -->
 
<!-- GIDEROSOBJ:Threads -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform pc.png]][[File:Platform mac.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform pc.png]][[File:Platform mac.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
<br/>
+
'''Available since:''' 2018.10<br/>
'''<translate>Available since</translate>:''' 2018.12<br/>
 
<br/>
 
=== <translate>Description</translate> ===
 
<translate>The Threads plugin provides the ability to run Lua code in separate threads, taking advantage of multiple cores where available.
 
</translate><br/>
 
=== <translate>Examples</translate> ===<br/>
 
  
'''Simple example of one thread sleeping'''<br/>
+
=== Description ===
<source lang="lua">require "Threads"
+
 
 +
'''!!! THE THREAD PLUGIN WAS DEPRECATED IN GIDEROS 2022.10 !!!'''
 +
 
 +
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 a thread'''
 +
<syntaxhighlight lang="lua">
 +
require "Threads"
 
local thread = Thread.new()
 
local thread = Thread.new()
thread:setFunction(function() Thread.sleepFor(100000) end)
+
thread:setFunction(function()
 +
local a = 0
 +
for i = 1, 10000000 do
 +
a += 1
 +
end
 +
return i
 +
end)
 
thread:execute()
 
thread:execute()
 
local ok = false
 
local ok = false
 
while not ok do
 
while not ok do
  ok = thread:getResult()
+
ok = thread:getResult()
 
end
 
end
print("woot")
+
print("woot!")
</source>
+
</syntaxhighlight>
  
{|-
+
=== Class ===
| style="width: 50%; vertical-align:top;"|
+
[[Thread]]<br/>
  
=== <translate>Methods</translate> ===
+
{{Thread}}
[[Special:MyLanguage/Thread.new/Thread.new]]  ''<translate>Create a new thread</translate>''<br/><!-- GIDEROSMTD:Thread.new() Create a new thread -->
 
[[Special:MyLanguage/Thread:setFunction/Thread:setFunction]]  ''<translate>Sets Lua function that thread will execute.</translate>''<br/><!-- GIDEROSMTD:Thread:setFunction() Sets Lua function that thread will execute. -->
 
[[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. -->
 
| style="width: 50%; vertical-align:top;"|
 
=== blah ===
 
|}
 

Latest revision as of 05:06, 7 June 2025

Supported platforms: Platform android.pngPlatform ios.pngPlatform pc.pngPlatform mac.pngPlatform winrt.pngPlatform win32.png
Available since: 2018.10

Description

!!! THE THREAD PLUGIN WAS DEPRECATED IN GIDEROS 2022.10 !!!

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