Difference between revisions of "X Threads"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(One intermediate revision by one other user 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/>
'''<translate>Available since</translate>:''' 2018.10<br/>
+
'''Available since:''' 2018.10<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>Example</translate> ===
 
  
'''Simple example of getting result from thread.'''<br/>
+
=== Description ===
<source lang="lua">require "Threads"
+
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:setFunction(function()
  local a = 0
+
local a = 0
  for i = 1, 10000000 do
+
for i = 1, 10000000 do
    a += 1
+
a += 1
  end
+
end
  return i
+
return i
 
end)
 
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>
 
</source>
  
=== <translate>Class</translate> ===
+
=== Class ===
[[Special:MyLanguage/Thread|Thread]]<br/>
+
[[Thread]]<br/>
  
 
{{Thread}}
 
{{Thread}}

Latest revision as of 14:32, 13 July 2023

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 a thread <syntaxhighlight lang="lua"> 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!") </source>

Class

Thread