Thread function userdata

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CEN

I have a question about the following page of Godot documentation on using Threads

https://docs.godotengine.org/en/stable/tutorials/performance/threads/using_multiple_threads.html

The function at the following following line of the sample code:

func _thread_function(userdata):

is taking a userdata argument, but this is a function that is called once, when the thread starts

Question: how do you pass this userdata argument to _thread_function function? Is this a mistake in the documentation or is there a way to pass userdata argument to the main function of a thread each time the thread is unblocked?

:bust_in_silhouette: Reply From: aXu_AP

Read the previous line plus comments in the example:

# Third argument is optional userdata, it can be any variable.
thread.start(self, "_thread_function", "Wafflecopter")

# The argument is the userdata passed from start().

Here "Wafflecopter" is the data passed to the function. If you want to pass multiple parameters use Dictionary or Array as userdata.

Yes, you’re right. I was looking only at the Semaphore section, where the origin of userdata is not mentioned, & didn’t realize the code examples were incremental. Cheers.

CEN | 2022-09-19 10:10

By the way, the following comment

# If no argument was passed, this one still needs to
# be here and it will be null.

doesn’t seem to be valid anymore as I my thread_function does not have any arguments yet it is working

CEN | 2022-09-19 10:15

If that’s the case you could make an issue about it at GitHub - godotengine/godot-docs: Godot Engine official documentation

aXu_AP | 2022-09-19 12:37