Are threads and instances the same thing?

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

So, let’s just say I have a chess game. I want to create an analyzer that analyzes a series of possible moves, from different starting positions.

I’ve thought of two possible ways to do this:

  1. Use an instance
  2. Use multi-threading (which I’m not quite familiar with yet)

For the instanced method (which I’m not sure will work), I will create a separate scene, and in that separate scene create a script and a function called:

func _analyze_game(starting_pos):

Which, preferably, would calculate a series of possible moves starting from a specified chess board position.

Back to the main scene, I would instance a series of these analyzers, and give them each a starting position, and as they work out the probabilities I would sit back and enjoy my drink.

I’m not sure if this is an acceptable way to do this. I could also use multi-threading (which I don’t quite understand), but this brings me to the question: If I use the instances like this, isn’t this basically the concept of multi-threading (I think)?

Any better solutions to this analyzer problem would be welcomed.

Thanks for your time.

:bust_in_silhouette: Reply From: timothybrentwood

A thread can only process one thing at a time. Unless you instance() a Thread object and start() it, by default your game is single threaded.

An instance is more or less just a pointer to a spot in memory that contains all the stuff your scene has (variables) and can do (functions).

In your case you want to create a multi-threaded game. The concept of multi-threading is a bit too complex to explain in this small text box (but don’t dissuade that from you learning it).

Here are the docs regarding multi-threading in godot:

Multi-threading is a universal programming concept so it may be helpful for you to go outside of the godot sphere to learn how to create a multi-threaded application then try to incorporate what you learned into gdscript.

Thanks for the answer!

TheJokingJack | 2021-07-11 22:56