What does new Thread(functionName) do?
If I try new Thread(functionA); new Thread(function B); would both function A and B be running at the same time on different threads?
... and how many new threads can you run? Is there a way to do a try catch for this, to check if the thread can be started without danger?
Answer by asafsitner
Jul 08, 2012 at 08:13 AM
new Thread(functionName) does exactly what you expect it to - it starts a new thread that runs the specified function. So in your example yes, functionA and functionB would be running in parallel on different threads.
This can cause very interesting bugs, especially when more than one thread tries to access the same resource.
If you want to delve in multi-threading, which is a fascinating and extremely useful aspect of modern programming, I suggest you start with this tutorial and go from there.
HOWEVER! Unity is strictly single-threaded and from what I've seen trying to start a new thread from within Unity will cause everything to explode (i.e. give an error and stop working. It wouldn't, you know, REALLY explode...)
There is a theoretical limit of 2048 threads on a 32-bit windows system.
There is also a theoretical limit of threads in a 64-bit windows system, however it is obviously much larger and there is no reason you should ever need to reach it.
As you can guess, the thread count is limited by available memory.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
6 People are following this question.
How to prevent heavy method calculation from locking Unity up?
Thread ending prematurely?
Performing "transform.Rotate" in it's own thread
Runtime error printing another thread
Getting current time from the worker thread