?? barriersynch.java
字號:
/* ========================================================= Class to implement barrier sychronisation. iveArrived(i) decrements this count and notifies All the parameter is an id -- not necessary, but useful for tracing =========================================================*/public class BarrierSynch{ int WaitingOn = 0; int ThreadsLeft = 0; /* ======================================================== CONSTRUCTOR Set the number of threads waiting to Wait Count argument ======================================================== */ public BarrierSynch(int WaitCount){ WaitingOn = WaitCount; ThreadsLeft = WaitCount; System.out.println("New Barrier " +"="+ WaitingOn); } /* ================================================ Decrement the count of threads outstanding. Conditionally decrement the count of threads to wait for next time. if the count is zero tell everyone to wake up If the count is more than zero then just wait() The count should never be less than zero. ================================================ */ public synchronized void iveArrived(int ident){ if (WaitingOn > 0){ WaitingOn--; };//System.out.println("WAITING DECR " + WaitingOn + ident); if (WaitingOn == 0){ // wake up everyone waiting on this barrier notifyAll(); } else{ System.out.println("WAITING " + ident); //TRACE: waiting in barrier try{ wait();} catch (InterruptedException e) { }; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -