void DoWork(InstanceList task) { if (task.instances.Count <= 0) { return; } if (threadCount <= 0) { foreach (var i in task.instances) { i.SuperStep(); } return; } currentTask = task; monitor_workers.Set(); // Wait until all threads have started if (!monitor_main.WaitOne(34)) { Debug.LogError("One or more threads did not start."); } monitor_main.Reset(); monitor_workers.Reset(); // Wait until all threads have finished if (!monitor_main.WaitOne(1000)) { Debug.LogError("Deadlock or loop detected."); } monitor_main.Reset(); task.Reset(); if (available != threadCount) { Debug.Log(available); } }