fork download
  1. using UnityEngine;
  2. using UnityThreading;
  3.  
  4. public class UTHTest : MonoBehaviour {
  5.  
  6. TaskDistributor _distributor = new TaskDistributor("TestDistributor", 8, false);
  7. System.Random random = new System.Random();
  8. int sortedArrays = 0;
  9. bool isCalculating = false;
  10.  
  11. void Awake()
  12. {
  13. UnityThreadHelper.EnsureHelper();
  14.  
  15. isCalculating = true;
  16. //20 tasks
  17.  
  18. for (int t = 0; t < 20; t++)
  19.  
  20. {
  21.  
  22. //add them
  23.  
  24. _distributor.Dispatch(() =>
  25.  
  26. {
  27.  
  28.  
  29.  
  30.  
  31.  
  32. //work
  33.  
  34. //******************************
  35.  
  36. int[][] arrays = new int[random.Next(500, 1000)][];
  37.  
  38. for (int i = 0; i < arrays.Length; ++i)
  39.  
  40. {
  41.  
  42. arrays[i] = new int[random.Next(500, 10000)];
  43.  
  44. for (int k = 0; k < arrays[i].Length; ++k)
  45.  
  46. arrays[i][k] = random.Next(10000);
  47.  
  48. }
  49.  
  50.  
  51.  
  52. for (int i = 0; i < arrays.Length; ++i)
  53.  
  54. {
  55.  
  56. var index = i;
  57.  
  58.  
  59.  
  60.  
  61.  
  62. System.Array.Sort(arrays[index]);
  63.  
  64. System.Threading.Interlocked.Increment(ref sortedArrays);
  65.  
  66.  
  67. if (sortedArrays == arrays.Length)
  68.  
  69. {
  70.  
  71. isCalculating = false;
  72.  
  73. sortedArrays = 0;
  74.  
  75. }
  76.  
  77. }
  78.  
  79. //System.Threading.Thread.Sleep(2000);
  80. //********************************
  81.  
  82. string name = string.Format("Task {0} complete", Task.Current.Name);
  83.  
  84. //when this task is done, update the GUI with our results
  85. UnityThreadHelper.Dispatcher.Dispatch(() =>
  86. {
  87. GameObject obj = new GameObject(name);
  88.  
  89. }).Wait();
  90.  
  91. });
  92.  
  93. }
  94. }
  95.  
  96. void OnGUI()
  97. {
  98. if (GUILayout.Button(_distributor.TaskCount.ToString()))
  99. Run();
  100. }
  101.  
  102. void OnDestroy()
  103. {
  104. _distributor.Dispose();
  105. }
  106.  
  107. void Run()
  108. {
  109.  
  110.  
  111.  
  112.  
  113. _distributor.Start();
  114. }
  115. }
  116.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
using UnityEngine;
^
Main.java:2: error: class, interface, or enum expected
using System.Collections;
^
Main.java:3: error: class, interface, or enum expected
using UnityThreading;
^
Main.java:5: error: '{' expected
public class UTHTest : MonoBehaviour {
                    ^
Main.java:25: error: illegal start of expression
                _distributor.Dispatch(() =>
                                       ^
Main.java:25: error: illegal start of expression
                _distributor.Dispatch(() =>
                                          ^
Main.java:27: error: illegal start of expression
                {
                ^
Main.java:27: error: ';' expected
                {
                 ^
Main.java:37: error: illegal start of expression
                    int[][] arrays = new int[random.Next(500, 1000)][];
                       ^
Main.java:37: error: ';' expected
                    int[][] arrays = new int[random.Next(500, 1000)][];
                        ^
Main.java:37: error: illegal start of expression
                    int[][] arrays = new int[random.Next(500, 1000)][];
                         ^
Main.java:37: error: ';' expected
                    int[][] arrays = new int[random.Next(500, 1000)][];
                          ^
Main.java:65: error: ')' expected
                        System.Threading.Interlocked.Increment(ref sortedArrays);
                                                                  ^
Main.java:65: error: illegal start of expression
                        System.Threading.Interlocked.Increment(ref sortedArrays);
                                                                               ^
Main.java:86: error: illegal start of expression
					UnityThreadHelper.Dispatcher.Dispatch(() =>
					                                       ^
Main.java:86: error: illegal start of expression
					UnityThreadHelper.Dispatcher.Dispatch(() =>
					                                          ^
Main.java:87: error: illegal start of expression
                    {
                    ^
Main.java:87: error: ';' expected
                    {
                     ^
Main.java:90: error: illegal start of expression
                    }).Wait();
                     ^
Main.java:90: error: illegal start of expression
                    }).Wait();
                      ^
Main.java:90: error: ';' expected
                    }).Wait();
                           ^
Main.java:92: error: illegal start of type
                });
                 ^
Main.java:95: error: class, interface, or enum expected
	}
	^
Main.java:101: error: class, interface, or enum expected
	}
	^
Main.java:106: error: class, interface, or enum expected
	}
	^
Main.java:115: error: class, interface, or enum expected
	}
	^
26 errors
stdout
Standard output is empty