07-16-2019 07:48 PM
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start ()
{
for (int i = 0; i < 8; i++)
{
ThreadStart method = () => threadWork();
Thread thread = new Thread(method);
thread.Start();
}
void Update()
{
long sum = 0;
for (int i = 0; i < 1000000; ++i)
sum = (int)((sum + i) * 2.0f / 2.0f);
}
void threadWork()
{
while (true)
{
long sum = 0;
for (int i = 0; i < 100000000; ++i)
sum = (int)((sum + i) * 2.0f / 2.0f);
Debug.LogFormat("TestThread End name:{0} curr thread id:{1} cur timeStamp:{2}", sum, Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString());
}
}
}