int main() { nodePtr tree=NULL; char word[256]; while( (scanf("%s", word)) != EOF ) tree = worker (word, tree); emOrdem(tree); eraseTree(tree); return 0; }
int main(int argc, char *argv[]) { //JarvisService service(argc, argv); //return service.exec(); QApplication app(argc, argv); Client client; InputWorker worker(client); QThread thread; worker.moveToThread(&thread); thread.start(); QMetaObject::invokeMethod(&worker, "doWork", Qt::QueuedConnection); app.exec(); }
int main() { /* Test whether finished coroutine can be canceled. */ int cr = go(worker()); errno_assert(cr >= 0); int rc = hclose(cr); errno_assert(rc == 0); /* Let the test running for a while to detect possible errors if there was a bug that left any corotines running. */ rc = msleep(now() + 100); errno_assert(rc == 0); return 0; }
int getWorkerTime() { int cnt, i; struct timeval tv1, tv2; cnt = 0; gettimeofday(&tv1, NULL); gettimeofday(&tv2, NULL); // Warmup of 1 sec while (1000000 > timeDiff(&tv1, &tv2)) { i = worker(); usleep(1); gettimeofday(&tv2, NULL); } gettimeofday(&tv1, NULL); gettimeofday(&tv2, NULL); // Meassure for 4 sec while (4*1000000 > timeDiff(&tv1, &tv2)) { i = worker(); usleep(0); gettimeofday(&tv2, NULL); cnt++; } return timeDiff(&tv1, &tv2)/cnt; }
void GameEventMgr::UpdateCreatureData(int16 event_id, bool activate) { for (GameEventCreatureDataList::iterator itr = mGameEventCreatureData[event_id].begin(); itr != mGameEventCreatureData[event_id].end(); ++itr) { // Remove the creature from grid CreatureData const* data = sObjectMgr.GetCreatureData(itr->first); if (!data) continue; // Update if spawned GameEventUpdateCreatureDataInMapsWorker worker(data->GetObjectGuid(itr->first), data, &itr->second, activate); sMapMgr.DoForAllMapsWithMapId(data->mapid, worker); } }
void worker(long long int A[],long long int j) //Goes up the tree swapping with the parent wherever required. { long long int temp; if(j>=2) { if(A[j/2]<A[j]) { temp=A[j/2]; A[j/2]=A[j]; A[j]=temp; worker(A,j/2); } } }
int main(int argc, const char **argv) { std::cout << "In main()\n"; boost::asio::io_service io; controller c(io); boost::thread worker(work, boost::ref(io)); boost::this_thread::sleep(boost::posix_time::seconds(5)); // c.testdb(); io.run(); c.qosThread->join(); worker.join(); std::cout << "[main] goodbye\n"; }
Worker::Worker(std::size_t count) { util::ThreadContext context = {"Worker", util::ThreadType::Worker, util::ThreadPriority::Low}; for (std::size_t i = 0; i < count; i++) { std::unique_ptr<util::Thread<Impl>> worker(new util::Thread<Impl>(context)); // FIXME: Workers should not access the FileSource but it // is currently needed because of GlyphsPBF. See #1664. auto task = std::make_shared<WorkTask>([fs = util::ThreadContext::getFileSource()]{ util::ThreadContext::setFileSource(fs); }, []{}); worker->invoke(&Worker::Impl::doWork, task); threads.emplace_back(std::move(worker)); } }
INT WINAPI WinMain( HINSTANCE , HINSTANCE, LPSTR , INT ) { int imageWidth = 43200; int imageHeight = 21600; string inputFile = "earth_diffuse_1km_shaded_RGB.raw"; string outputFile = "earth_diffuse_1km_shaded.ecw"; cout << "Input file: " << inputFile << " Output file: " << outputFile << endl; CNCSFile::SetKeySize(); CompressWorker worker(inputFile, outputFile, imageWidth, imageHeight); CNCSError error = worker.Write(); string errorMessage = error.GetErrorMessage(); }
int main(int argc, char *argv[]) { const int maxtask = 40; int rank; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) master(maxtask); else worker(); MPI_Finalize(); }
NodeVersionLoader::NodeVersionLoader(const boost::asio::ip::tcp::endpoint &ep): thread([this] { worker(); }), service(), disposed(false), socket(service), endpoint(ep), state(State::Idle), timer(service), readBuffer(16384) { log.setChannel(std::string("(none)")); work.reset(new boost::asio::io_service::work(service)); }
static pid_t spawn_worker() { pid_t pid; if ((pid = fork()) < 0) { return -1; } if (pid == 0) { int ret = worker(); _exit(ret); } return pid; }
int exec_socks5(int fd) { int pid; pid = fork(); if(pid>0){ close(fd); exit(0); } int flags = fcntl(fd,F_GETFL,0); flags &= ~O_NONBLOCK; fcntl(fd,F_SETFL,flags); worker(fd); exit(0); }
int main(/*int argc, char *argv[]*/) { // Sytyi // MGUAP worker(FUNCTION_1, CRITERIA_MIN_STD_DEVIATION, STOP_AVERAGE); // Vlasenko // MGUAP worker(FUNCTION_1, CRITERIA_MIN_STD_DEVIATION, STOP_MAXIMUM); // Irko // MGUAP worker(FUNCTION_2, CRITERIA_MAX_COEFF_CORELATION, STOP_ABS_DEVIATION); // Alkal0id or Raneyd // please look to taskdefines.h and uncomment #define UNBIAS MGUAP worker(FUNCTION_3, CRITERIA_UNBIASED_SOLUTIONS, STOP_AVERAGE_UNBIAS); worker.Run(); return 0; }
/* * main loop - construct the event_base and start the loop */ int run_server(char* ip, short port, int timeout_s, int backlog) { struct event_base *ev_base; struct event_config *ev_cfg; struct evhttp *ev_httpd; evutil_socket_t socket_fd; int socket_opts_flag = 1; int worker_id, socket_opts_results; openlog("Backend", LOG_PID|LOG_NDELAY, LOG_LOCAL0); ev_cfg = event_config_new(); //event_config_set_flag(ev_cfg, EV_TIMEOUT|EV_PERSIST); ev_base = event_base_new_with_config(ev_cfg); if (!ev_base) { printf("ERROR: Failed to initialize HTTP event loop!\n"); return -1; } // Set up httpd interface event ev_httpd = evhttp_new(ev_base); evhttp_set_timeout(ev_httpd, timeout_s); routes(ev_httpd, ev_base); socket_fd = create_socket(ip, port, timeout_s, backlog); socket_opts_results = setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (char *) socket_opts_flag, sizeof(int)); if ( socket_opts_results < 0 ) { syslog( LOG_INFO, "Nagle DISABLED"); } else { syslog( LOG_INFO, "Nagle ENABLED"); } evhttp_accept_socket(ev_httpd, socket_fd); for (worker_id = 0; worker_id < WORKERS; worker_id++) { if (fork() == 0) { printf("Starting worker_id %d ... ", worker_id); worker(ev_base); printf("done.\n"); exit(0); } } closelog(); return 0; }
int do_fork(int m) { pid_t pid; pid = fork(); if (pid < 0) { perror("fork"); //kill(0,SIGUSR1); return -1; //sleep(1); } else if (pid == 0) { // child worker(m); exit(0); } //parent return 0; }
int main() { initList(N_MAX_LINKS); char word[256]; while( (scanf("%s", word)) != EOF ) worker(word); printList(list->next[0]); freeMem(); printf("t->%d\n", t); return 0; }
int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("Forensics-Data-Extractor"); QCoreApplication::setApplicationName("Extractor"); QThreadPool thread_pool; QString db_file; zmq::context_t zmq_context(1); if ( argc < 3 ) { usage(); return EXIT_FAILURE; } if ( strcmp(argv[1], "-d" ) == 0 ) { db_file = argv[2]; } else { usage(); return EXIT_FAILURE; } Database database(db_file); Receiver receiver((void*)&zmq_context, ZMQ_INPROC_URL, &database); Worker worker((void*) &zmq_context, &database, ZMQ_INPROC_URL); try { struct_file file; receiver.start(); while ( database.walk_files_to_extract(file) == true ) { worker.start(); worker.wait(); } } catch (std::exception& e) { std::cerr << e.what(); return EXIT_FAILURE; } send_zmq(zmq_context, ZMQ_INPROC_URL, ZMQ_PUSH, "END;"); // thread_pool.waitForDone(); receiver.wait(); std::cout << database.get_row_count("analysed_file") << " files analysed" << std::endl; std::cout << thread_pool.maxThreadCount() << " threads used" << std::endl; return EXIT_SUCCESS; }
WEAK void do_par_for(void (*f)(int, uint8_t *), int min, int size, uint8_t *closure) { static bool thread_pool_initialized = false; if (!thread_pool_initialized) { pthread_mutex_init(&work_queue.mutex, NULL); pthread_cond_init(&work_queue.not_empty, NULL); work_queue.head = work_queue.tail = 0; work_queue.ids = 1; char *threadStr = getenv("HL_NUMTHREADS"); threads = 8; if (threadStr) { threads = atoi(threadStr); } else { printf("HL_NUMTHREADS not defined. Defaulting to 8 threads.\n"); } if (threads > MAX_THREADS) threads = MAX_THREADS; for (int i = 0; i < threads-1; i++) { //fprintf(stderr, "Creating thread %d\n", i); pthread_create(work_queue.threads + i, NULL, worker, NULL); } thread_pool_initialized = true; } // Enqueue the job pthread_mutex_lock(&work_queue.mutex); //fprintf(stderr, "Enqueuing some work\n"); work job = {f, min, min + size, closure, work_queue.ids++, 0}; if (job.id == 0) job.id = work_queue.ids++; // disallow zero, as it flags a completed job work_queue.jobs[work_queue.tail] = job; work *jobPtr = work_queue.jobs + work_queue.tail; worker_arg arg = {job.id, jobPtr}; int new_tail = (work_queue.tail + 1) % MAX_JOBS; assert(new_tail != work_queue.head); work_queue.tail = new_tail; // TODO: check to make sure the work queue doesn't overflow pthread_mutex_unlock(&work_queue.mutex); //fprintf(stderr, "Waking up workers\n"); // Wake up everyone pthread_cond_broadcast(&work_queue.not_empty); // Do some work myself //fprintf(stderr, "Doing some work on job %d\n", arg.id); worker((void *)(&arg)); //fprintf(stderr, "Parallel for done\n"); }
int main(int argc, char** argv) { int len; char opt; int output_options=0; char filename[256]=""; // it should be enough while ((opt=getopt(argc,argv,"hdqf:"))!=-1) { switch(opt) { case 'h': print_help("hdqf:"); return 0; DQ_OPTIONS_BLOCK case 'f': strcpy(filename,optarg); break; case '?': return 1; default: break; } } if (optind==argc) { printf("No length specified\n"); return 1; } if (optind+1==argc) { len = atoi(argv[optind]); } else { printf("Too many arguments:\n"); while (argv[optind]!=NULL) { printf("%s ", argv[optind]); optind++; } printf("\n"); return 1; } if (len<1) { printf("Improper gem number\n"); return 1; } if (filename[0]=='\0') strcpy(filename, "table_leech"); worker(len, output_options, filename); return 0; }
void read_cb(struct bufferevent *bev, void *arg) { #define MAX_LINE 2560 char line[MAX_LINE + 1]; char output[1000]; int n; evutil_socket_t fd = bufferevent_getfd(bev); while (n = bufferevent_read(bev, line, MAX_LINE), n > 0) { line[n] = '\0'; printf("fd=%u, read line: %s\n", fd, line); worker((int) fd, line, output); printf("out line: %s,len=%d\n", output,strlen(output)); bufferevent_write(bev, output, strlen(output)); } //close(fd); }
int driver(const char *input_file, const char *output_file) { char end_str[4]; int case_num; FILE *fp = fopen(input_file,"r"); if(!fp) { printf("open failed.\n"); return 1; } result_cnt = 0; while(!feof(fp)) { fscanf(fp, "%d", &case_num); int i = 0; while(i<9) { fscanf(fp, "%s", &map[i*9]); i++; } fscanf(fp, "%s\n", end_str); char s[82]; int score = 0; int ret = false; result[result_cnt].case_num = case_num; memset(s,0,sizeof(s)); ret = worker(map,s,score); if(ret == true) { result[result_cnt].score = score; strcpy(result[result_cnt].s, s); } else { result[result_cnt].score = 0; } result_cnt++; } //output_parse(output_file, result,result_cnt); output_to_cmd(result,result_cnt); fclose(fp); return 0; }
void DNSHandler::worker_func () noexcept { try { worker(); } catch (...) { try { panic(std::current_exception()); } catch (...) { } } }
void SingleThreadDispatcher::dispatch(const renderer::RenderContext& context, std::shared_ptr<util::IProgressHandler> progress) { int render_tiles = context.tile_set->getRequiredRenderTilesCount(); if (render_tiles == 0) return; LOG(INFO) << "Single thread will render " << render_tiles << " render tiles."; renderer::RenderWork work; work.tiles.insert(renderer::TilePath()); renderer::TileRenderWorker worker; worker.setRenderContext(context); worker.setRenderWork(work); worker.setProgressHandler(progress); worker(); }
void ADThreadPool::start() { if(workers.size() < _threads) { for(size_t i = 0;i<_threads;++i) { auto cond = condition; auto mutex = queue_mutex; //workers_finished.push_back(false); workers.push_back(std::make_shared<std::thread>([this,i,cond,mutex](){ worker(i, cond, mutex); //workers_finished[i] = true; //cocos2d::CCLog("Exit 2: %d", i); })); } } }
bool SystemCmdSound::Play() { #ifdef _DEBUG wxLogInfo("SystemCmdSound::Play()"); #endif /* _DEBUG */ if (m_isPlaying) { wxLogWarning("SystemCmdSound: cannot play: already playing"); return false; } if (m_onFinished) { std::thread t([this]() { worker(); }); t.detach(); return true; } int r = do_play(m_cmd.c_str(), m_path.c_str()); return r == 0; }
void Server::acceptClient(){ struct sockaddr_in saddr; socklen_t ssize = 0; memset(&saddr, 0, sizeof(saddr)); int cfd = accept(sfd , reinterpret_cast<sockaddr*>(&saddr), &ssize); if(-1 == cfd){ LoggerST::Instance()->Err("accept()"); return; } char buf[INET_ADDRSTRLEN]; if(NULL == inet_ntop(AF_INET,&saddr, buf, INET_ADDRSTRLEN)){ LoggerST::Instance()->Err("inet_ntop()"); return; } LoggerST::Instance()->Msg("accepted client: fd[%d] from[%s:%d]", cfd, buf, ntohs(saddr.sin_port)); worker(cfd); }
int main(int argc, char* argv[]) { try { log_init(); cxxtools::Arg<const char*> ip(argc, argv, 'i', "0.0.0.0"); cxxtools::Arg<unsigned short> port(argc, argv, 'p', 1234); cxxtools::Arg<unsigned> bufsize(argc, argv, 'b', 8192); cxxtools::Arg<bool> listen(argc, argv, 'l'); cxxtools::Arg<bool> read_reply(argc, argv, 'r'); if (listen) { // I'm a server // listen to a port cxxtools::net::Server server(ip.getValue(), port); // accept a connetion cxxtools::net::iostream worker(server, bufsize); // copy to stdout std::cout << worker.rdbuf(); } else { // I'm a client // connect to server cxxtools::net::iostream peer(ip, port, bufsize); // copy stdin to server peer << std::cin.rdbuf() << std::flush; if (read_reply) // copy answer to stdout std::cout << peer.rdbuf() << std::flush; } } catch (const std::exception& e) { std::cerr << e.what() << std::endl; } }
void MapPersistentStateManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, uint32 timeLeft) { // global reset for all instances of the given map MapEntry const* mapEntry = sMapStore.LookupEntry(mapid); if (!mapEntry->IsDungeon()) return; time_t now = time(NULL); if (!warn) { MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapid, difficulty); if (!mapDiff || !mapDiff->resetTime) { sLog.outError("MapPersistentStateManager::ResetOrWarnAll: not valid difficulty or no reset delay for map %d", mapid); return; } // remove all binds for online player for (PersistentStateMap::iterator itr = m_instanceSaveByInstanceId.begin(); itr != m_instanceSaveByInstanceId.end(); ++itr) if (itr->second->GetMapId() == mapid && itr->second->GetDifficulty() == difficulty) ((DungeonPersistentState*)(itr->second))->UnbindThisState(); // reset maps, teleport player automaticaly to their homebinds and unload maps MapPersistantStateResetWorker worker; sMapMgr.DoForAllMapsWithMapId(mapid, worker); // delete them from the DB, even if not loaded CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM character_instance USING character_instance LEFT JOIN instance ON character_instance.instance = id WHERE map = '%u'", mapid); CharacterDatabase.PExecute("DELETE FROM group_instance USING group_instance LEFT JOIN instance ON group_instance.instance = id WHERE map = '%u'", mapid); CharacterDatabase.PExecute("DELETE FROM instance WHERE map = '%u'", mapid); CharacterDatabase.CommitTransaction(); // calculate the next reset time time_t next_reset = DungeonResetScheduler::CalculateNextResetTime(mapDiff, now + timeLeft); // update it in the DB CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '" UI64FMTD "' WHERE mapid = '%u' AND difficulty = '%u'", (uint64)next_reset, mapid, difficulty); return; } // note: this isn't fast but it's meant to be executed very rarely MapPersistantStateWarnWorker worker(timeLeft); sMapMgr.DoForAllMapsWithMapId(mapid, worker); }
int main(int argc, char** argv) { int len; char opt; int pool_zero=2; // speccing by default int output_options=0; while ((opt=getopt(argc,argv,"hptecidqur"))!=-1) { switch(opt) { case 'h': print_help("hptecidqur"); return 0; PTECIDQUR_OPTIONS_BLOCK case '?': return 1; default: break; } } if (optind==argc) { printf("No length specified\n"); return 1; } if (optind+1==argc) { len = atoi(argv[optind]); char* p=argv[optind]; while (*p != '\0') p++; if (*(p-1)=='c') pool_zero=1; } else { printf("Too many arguments:\n"); while (argv[optind]!=NULL) { printf("%s ", argv[optind]); optind++; } printf("\n"); return 1; } if (len<1) { printf("Improper gem number\n"); return 1; } worker(len, output_options, pool_zero); return 0; }