static void * worker_thread_func( void * ptr ) { if(!ptr) return NULL; Worker* worker = (Worker*) ptr; int ret = worker->Start(); return (void*) ret; }
void WorkScheduler::Start(Pocket::IDelegate<WorkerContext *> *workMethod, Pocket::IDelegate<WorkerContext *> *finishedMethod, Pocket::IDelegate<Worker*>* progressChanged) { Worker* worker = new Worker(); workers.push_back(worker); worker->Start(workMethod, finishedMethod); worker->JobDone += event_handler(this, &WorkScheduler::WorkerFinished); if (progressChanged) worker->Progress.Changed += progressChanged; }
int main(int argc, char* argv[]) { ArgumentParser::Parse(argc, argv); Traces::SetTraceFolder(ProgramVariables::GetLogDirectory() + "/trace"); Worker worker; worker.Start(); return 0; }
int main() { Worker w; { // thread A auto o = boost::make_shared<Object>(); signals2::connection bc = w.Signal.connect(bind(&Object::doSomething, o)); w.Start(); this_thread::sleep(posix_time::seconds(2)); bc.disconnect(); } return 0; }
int Process(int worker) { //int port = atoi(server_config[1]); int count = 0; pid_t pid[10], pid_monitor; int res, status; Worker *w = NULL; while (count < worker) { res = pipe(pipe_fd[count]); sys_assert(res, "pipe"); pid[count] = fork(); switch(pid[count]) { case -1: sys_assert(pid[count], "fork"); break; case 0: w = new Worker(server_ip, server_port); res_assert((void*)w, "process"); w->m_info.set_rpipe(pipe_fd[count][0]); w->m_info.set_id(count); close(pipe_fd[count][1]); w->Start(); delete w; w = NULL; break; default: close(pipe_fd[count][0]); count++; printf("success child %d\n", count); } } if (pid[count - 1]) { UserMoniter(); for (count = 0; count < worker; ++count) { waitpid(pid[count], &status, 0); } LOG(stderr, "child all stop\n"); } }
int main(int argc, char* argv[]){ Worker wk; wk.Start(); return 0; }