int ProcessPool::WaitAll() { // TODO: 完成代码 int ret = 0; ProcessVec::iterator it = processes.end(); while (it != processes.begin()) { it --; Process* process = *it; if (process->Kill() != 0) { cout << "ProcessPool wait all failed in waitting process " << process->GetId() << endl; ret = -1; break; } delete process; it = processes.erase(it); } return ret; }
int ProcessPool::KillAll() { // TODO: 完成代码 ProcessVec::iterator it = processes.end(); while (it != processes.begin()) { it --; Process* process = *it; if (process->Kill() != 0) { cout << "ProcessPool kill all failed in killing process " << process->GetId() << endl; cout << errno << endl; return -1; } delete process; it = processes.erase(it); } return 0; }
int ProcessPool::Start(int procCount, Runnable& target) { //XXX // 去掉清空,可以支持一个进程池,执行多个任务 // processes.resize(procCount); for(int i = 0; i < procCount; i++){ Process* tmpProcess = new Process(target); tmpProcess->SetId(fork()); /* if (processes[i]->GetId() < 0){ processes.resize(i); // XXX // 只能创建那么多 return i; } */ if (tmpProcess->GetId() == 0){ tmpProcess->Start(); exit(0); } processes.push_back(tmpProcess); } return 0; }
static void checkExit (int messaging_result_code) { if (messaging_result_code == -ERROR_EXITING) { Process * process = THREAD_CURRENT()->process; process->LookupConnection(PROCMGR_CONNECTION_ID)->SendMessageAsync(PULSE_TYPE_CHILD_FINISH, process->GetId()); Thread::BeginTransaction(); Thread::MakeUnready(THREAD_CURRENT(), Thread::STATE_FINISHED); Thread::RunNextThread(); Thread::EndTransaction(); assert(false); } }