void ClassifyThreadProc(object par) { ClassifyObject p = (ClassifyObject)par; int start = -1; int end = -1; int c = p.cellids.Count; int ele = c / p.threadCount; if (p.threadCount != p.threadIndex + 1) { start = p.threadIndex * ele; end = start + ele - 1; } else { start = p.threadIndex * ele; end = c - 1; } int temp = 0; if (p.pos != null && p.pos.Count != 0) { temp = p.pos[0]; } for (int i = start; i <= end; i++) { int serverid = Global.CloudStorage.GetServerIdByCellId(p.cellids[i][temp]); p.classify[serverid].Add(p.cellids[i]); } }
/// <summary> /// 分类器 把行按照服务器分类 多线程 /// </summary> /// <param name="CELLIDS"></param> /// <param name="cond">条件表达式表示用到的行</param> /// <returns></returns> private List <List <List <long> > > Classify(List <List <long> > CELLIDS, List <int> cond) { List <List <List <long> > > classify = new List <List <List <long> > >(Global.CloudStorage.ServerCount); for (int i = 0; i < Global.CloudStorage.ServerCount; i++) { classify.Add(new List <List <long> >()); } int threadCount = Environment.ProcessorCount; Thread[] threadNum = new Thread[threadCount]; for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) { ClassifyObject p = new ClassifyObject(threadCount, threadIndex, CELLIDS, classify, cond); threadNum[threadIndex] = new Thread(ClassifyThreadProc); threadNum[threadIndex].Start(p); } for (int inde = 0; inde < threadCount; inde++) { threadNum[inde].Join(); } return(classify); }