• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Discussion What exactly is threaded in GMS?

Bingdom

Googledom
For the longest time, I was under the impression that GMS2 was multithreaded comprising of the main game loop, audio and at some point, asynchronous events.

However, I have been picking up an understanding of Coroutines and Async in other languages recently and it all has a common ground (at least the languages I worked with) to run on the same thread.

This made me question my assumption about asynchronous behaviour in GM.

Information about this is rather scarce and old (1, 2)

In addition, this blog seems to indicate that the GC runs on multiple threads.

So the question is- what exactly is threaded in GMS? Would the documentation be improved to include these details?

I'm also curious about how many threads the GC takes up, and what influences it to use more threads?
 
Last edited:

kburkhart84

Firehammer Games
Posting for the follow, skipping the "follow" button since I have a small comment.

I only know for sure that audio is on a separate thread. I'm pretty much sure that any external network loading functions(that then cause async events) also create separate threads. The GC may very well do so. However, unless I missed something, I seriously doubt that much of anything else is threaded. The thing that I think could be but doesn't seem to be is loading external assets locally, like sounds and sprites, and I don't think those open another thread because the functions return right away with valid references( unlike things loaded over network/internet).

Honestly, I wouldn't make any assumptions on everything related to async events being in a separate thread. I'd hazard a guess that the majority of those things are, as they involve audio, internet communication, etc... but the ones in the "system" category I'm not 100% on.

gamepads - I don't think they spawn a thread for this, but I could be wrong
virtual keyboards - I don't think they have a separate thread, although the OS itself that is controlling it would have it's own thread(s) for it.
XBOX Live - this is likely a separate thread under the same logic as the other internet stuff
audio system status - this is only for HTML5(though it triggers once on other platforms as well)...I'd assume it is on another thread like other audio stuff

This whole post is my speculation based on my observations. In summary, I understand that the runner is basically single threaded. But anything that communicates over the network, and anything related to audio(except possibly local audio loading) is likely on separate threads.
 

Juju

Member
Audio, and whatever operations the OS is doing that are inherently async. Reference finding for the garbage collector happens on the main thread though the actual sweep might be threaded. Everything else is on the main thread.

This may change in the new runtime.
 

rwkay

GameMaker Staff
GameMaker Dev.
What is multi-threaded on GMS2 is a bit complex as it varies per platform

* Audio - there is a mixing thread that takes all the active audio and mixes it into the output device (NOTE: depending on the platform there may be multiple devices active i.e. PS4 can mix into each pad and the main output device).
* Garbage Collector - objects are freed on a separate thread. (objects are identified on the main thread).
* OGG streaming - any ogg streams are decoded on a separate thread.
* Debugger - there is a thread active for the debugger (when it is being run)
* Audio capture - when recording from microphone there is a thread per capture device.

On some platforms there are various other threads that may be active depending on implementation (and functions used) e.g. Windows HTTP requests use a separate thread.

On other platforms we use ASync functions which may or may not use threads depending on the implementation on that platform (i.e. HTTP and async fle functions).

So it is not quite as clear cut as you may think.

Russell
 
Top