unity多執行緒2

TheAI發表於2017-12-19



接上回執行緒,再寫一個類,很簡單。

[csharp] view plain copy
  1. public class NewBehaviourScript : MonoBehaviour {  
  2.   
  3.     XianCheng xiancheng;  
  4.   
  5.     void Start () {  
  6.         xiancheng = new XianCheng();  
  7.         xiancheng.StartXianCheng();  
  8.     }  
  9.       
  10.   
  11.     void Update () {  
  12.          Debug.Log(xiancheng.queue.Count);  //lock的話,列印先1後2,不lock直接2,因為兩個執行緒同時使用了佇列。  
  13.     }  
  14.   
  15.       
  16.     void OnApplicationQuit()  
  17.     {  
  18.        xiancheng.ThreadTwo.Abort();               //終止執行緒1  
  19.        xiancheng.ThreadOne.Abort();               //終止執行緒2  
  20.     }  
  21. }  

相關文章