- Home /
How do I call a function in a different CPU core?
I wish I could just do this System.Threading.ActiveCore = 3
but how would I simply change the core?
Please don't give an answer like "You need to learn more... etc," do it as a comment.
Answer by Socapex · Dec 28, 2016 at 07:35 PM
So far (Unity is working on multithreading better), you can only spawn threads when you are not dealing with anything tied to MonoBehaviours or other Unity types. This renders multithreading quite useless for a lot of projects.
There is no good reason to specify a thread, the scheduler does that for you. The easiest way to launch an async is a simple anonymous thread with a lambda. This uses builtin C# threading.
Here is a very simple example so you can start dipping your toe in the nightmare which awaits you.
(new System.Threading.Thread(() => {
int test = 0;
while (test < 50) {
System.Threading.Thread.Sleep(100);
++test;
Debug.Log(test);
}
})).Start();
Try this in a normal C# class. You can make an Init() method or something to test it out.
Answer by AurimasBlazulionis · Dec 28, 2016 at 09:00 PM
Your OS controls what thread is being used. It automatically chooses the optimal CPU thread to use. And you have no control of it.