/// <summary> /// Once the SCC is found, we check whether the fairness condition is satisfied or not. /// </summary> /// <param name="StronglyConnectedComponents"></param> /// <returns></returns> private void StartFairThread(Dictionary <string, LocalPair> StronglyConnectedComponents) { /******************************************************************** * IMPORTANT: Be careful with the Stack copy constructor * It will make a new stack which is reversed of the original stack * So do not use Stack<LocalPair> newTaskStack = new Stack<LocalPair>(TaskStack); ********************************************************************/ Stack <LocalPair> newTaskStack = new Stack <LocalPair>(TaskStack.Count); LocalPair[] pairArray = TaskStack.ToArray(); for (int i = pairArray.Length - 1; i >= 0; i--) { newTaskStack.Push(pairArray[i]); } // This will reverse the order of the state in the stack //foreach (LocalPair pair in TaskStack) //{ // newTaskStack.Push(pair); //} // Copy the outgoing table Dictionary <string, List <string> > transTable = new Dictionary <string, List <string> >(1024); foreach (KeyValuePair <string, LocalPair> keyvaluePair in StronglyConnectedComponents) { string v = keyvaluePair.Key; transTable.Add(v, OutgoingTransitionTable[v]); } FairThread ft = new FairThread(StronglyConnectedComponents, newTaskStack, FairnessType, transTable); ThreadPool.AddThread(ft); //System.Threading.ThreadPool.QueueUserWorkItem(ft.Start); }
public PATThreadPool() { JobFinished = false; ResultThread = null; FinishedThread = 0; ThreadNumber = 0; }
public void AddThread(FairThread thread) { lock (WorkThreads) { if (!JobFinished) { ThreadNumber++; WorkThreads.Add(thread); thread.ReturnAction += new ReturnEvent(thread_ReturnAction); System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(thread.InternalStart), null); } } }
void thread_ReturnAction(FairThread fairThread) { lock (WorkThreads) { //WorkThreads.Remove(fairThread); if (fairThread.result) { ResultThread = fairThread; JobFinished = true; Tarjan.JobFinished = true; foreach (FairThread thread in WorkThreads) { thread.CancelRequested = true; } } fairThread.ReturnAction -= new ReturnEvent(thread_ReturnAction); FinishedThread++; ThreadNumber--; } }
/// <summary> /// Once the SCC is found, we check whether the fairness condition is satisfied or not. /// </summary> /// <param name="StronglyConnectedComponents"></param> /// <returns></returns> private void StartFairThread(Dictionary<string, LocalPair> StronglyConnectedComponents) { /******************************************************************** * IMPORTANT: Be careful with the Stack copy constructor * It will make a new stack which is reversed of the original stack * So do not use Stack<LocalPair> newTaskStack = new Stack<LocalPair>(TaskStack); ********************************************************************/ Stack<LocalPair> newTaskStack = new Stack<LocalPair>(TaskStack.Count); LocalPair[] pairArray = TaskStack.ToArray(); for (int i = pairArray.Length - 1; i >= 0; i--) { newTaskStack.Push(pairArray[i]); } // This will reverse the order of the state in the stack //foreach (LocalPair pair in TaskStack) //{ // newTaskStack.Push(pair); //} // Copy the outgoing table Dictionary<string, List<string>> transTable = new Dictionary<string, List<string>>(1024); foreach (KeyValuePair<string, LocalPair> keyvaluePair in StronglyConnectedComponents) { string v = keyvaluePair.Key; transTable.Add(v, OutgoingTransitionTable[v]); } FairThread ft = new FairThread(StronglyConnectedComponents, newTaskStack, FairnessType, transTable); ThreadPool.AddThread(ft); //System.Threading.ThreadPool.QueueUserWorkItem(ft.Start); }