Threading in Unity is "...virtual" ?! :D

Hello guys!

I am using about 100 threads in Editor, when they are calculating different tasks on the click of a button for about a minute or so

There is not interaction with Unity API, but if there are more than 100 threads, unity’s main thread tends to freeze.
When I open resource manager, it shows that CPU currently is 100% used by Unity, and the RAM used is 330 MB.

But it also shows that it is using 20 threads at maximum! (and is only 1 process)

Does that mean I am really not using threading, but just letting the processor to alternate between them quickly?

If so, what is the way to do threading?

for each of my threads, I am saying :

Thread t1 = new Thread(new ParameterizedThreadStart(Function1));
t1.Start(object FunctionArgument);

Thank you for help :slight_smile:

What you’re doing is a bad idea if you don’t run on serious multicore hardware. As the switching burns cpu too.

Also a lot of the synchronizing code you may be using, uses the default ThreadPool, like if you use Timers or BackgroundWorker or asynchronous delegates etc. And that pool is limited in Size.

You should shrink down your number of threads and queue your work, you don’t get more throughput by increasing thread counts anyway.

You could also search for some altenate Threadpool implementations. There are some nice ones out there.