Skip to content

Commit 808d100

Browse files
authored
Merge pull request godotengine#7483 from bitsawer/update_threading
2 parents 46bb76b + 43f9406 commit 808d100

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

tutorials/performance/using_multiple_threads.rst

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
:article_outdated: True
2-
31
.. _doc_using_multiple_threads:
42

53
Using multiple threads
@@ -29,23 +27,22 @@ To create a thread, use the following code:
2927
.. tabs::
3028
.. code-tab:: gdscript GDScript
3129

32-
var thread
30+
var thread: Thread
3331

3432
# The thread will start here.
3533
func _ready():
3634
thread = Thread.new()
37-
# Third argument is optional userdata, it can be any variable.
38-
thread.start(self, "_thread_function", "Wafflecopter")
35+
# You can bind multiple arguments to a function Callable.
36+
thread.start(_thread_function.bind("Wafflecopter"))
3937

4038

4139
# Run here and exit.
42-
# The argument is the userdata passed from start().
43-
# If no argument was passed, this one still needs to
44-
# be here and it will be null.
40+
# The argument is the bound data passed from start().
4541
func _thread_function(userdata):
4642
# Print the userdata ("Wafflecopter")
4743
print("I'm a thread! Userdata is: ", userdata)
4844

45+
4946
# Thread must be disposed (or "joined"), for portability.
5047
func _exit_tree():
5148
thread.wait_to_finish()
@@ -86,16 +83,16 @@ Here is an example of using a Mutex:
8683
.. tabs::
8784
.. code-tab:: gdscript GDScript
8885

89-
var counter = 0
90-
var mutex
91-
var thread
86+
var counter := 0
87+
var mutex: Mutex
88+
var thread: Thread
9289

9390

9491
# The thread will start here.
9592
func _ready():
9693
mutex = Mutex.new()
9794
thread = Thread.new()
98-
thread.start(self, "_thread_function")
95+
thread.start(_thread_function)
9996

10097
# Increase value, protect it with Mutex.
10198
mutex.lock()
@@ -104,7 +101,7 @@ Here is an example of using a Mutex:
104101

105102

106103
# Increment the value from the thread, too.
107-
func _thread_function(userdata):
104+
func _thread_function():
108105
mutex.lock()
109106
counter += 1
110107
mutex.unlock()
@@ -131,11 +128,11 @@ ready to be processed:
131128
.. tabs::
132129
.. code-tab:: gdscript GDScript
133130

134-
var counter = 0
135-
var mutex
136-
var semaphore
137-
var thread
138-
var exit_thread = false
131+
var counter := 0
132+
var mutex: Mutex
133+
var semaphore: Semaphore
134+
var thread: Thread
135+
var exit_thread := false
139136

140137

141138
# The thread will start here.
@@ -145,10 +142,10 @@ ready to be processed:
145142
exit_thread = false
146143

147144
thread = Thread.new()
148-
thread.start(self, "_thread_function")
145+
thread.start(_thread_function)
149146

150147

151-
func _thread_function(userdata):
148+
func _thread_function():
152149
while true:
153150
semaphore.wait() # Wait until posted.
154151

0 commit comments

Comments
 (0)