Multithreading

Is there a plan for allowing user-created scripts to use multiple threads?
How would it work? Any limitations? Any other thoughts?

5 Likes

I’m very much hoping this is planned, it would allow for so much more responsiveness and overall improve the feeling of content made on S&box.

Agreed, but we’re also going to be trusting the community to properly implement threading, that does scare me a little.

I can already see the addons using waits in their code to stop the random race conditions they encounter

2 Likes

you don’t create a thread for each time a player moves?

100% a concern, especially in people who are new to coding or the concept of threading.

I think its something that is worth the risk though, bad practices will be easily noticed performance wise so should encourage people to learn how to use threading properly and deter people from going on servers with said bad practices, again acting as that incentive to implement it properly.

1 Like

On Discord, Garry was asked about having UniTask to replace coroutines, to which he replied
image
Supposing this doesn’t get thrown away/blocked for “reasons”, multithreading would probably work with Task.Run or via other typical C# async stuff (ie awaiting async Task methods)

EDIT: Here’s a basic “guide” to async programming with C#

6 Likes