//static bool Timer_os::Init () { DWORD ThreadId; hWinEvent = CreateEvent (0, FALSE, FALSE, 0); hTimerThread = (HANDLE) CreateThread (0, 0, LPTHREAD_START_ROUTINE(TimerThread), 0, 0, &ThreadId); WaitForSingleObject (hWinEvent, INFINITE); CloseHandle (hWinEvent); hWinEvent = 0; return true; }
void CreateWorld() { surfaceShader = createShader("Shaders/SurfaceVertexShader.glsl", "Shaders/SurfacePixelShader.glsl", NULL); cloudsShader = createShader("Shaders/CloudsVertexShader.glsl", "Shaders/CloudsPixelShader.glsl", NULL); createCloudsMap(); createCloudsTexture(); initRootMapPatch(rootMapPatch, MapMin, MapMax); createPatchDisplayList(); InitializeCriticalSection(&queueCritSect); CreateThread(NULL, 0, LPTHREAD_START_ROUTINE(patchQueueThreadProc), NULL, 0, NULL); }
HANDLE RemoteThreadInjector::CallWithRemoteThread(LPVOID hModule, LPVOID lp_base_address) const { auto hRemoteHandle = CreateRemoteThread(m_hProcess, nullptr, 0, LPTHREAD_START_ROUTINE(hModule), lp_base_address, 0, nullptr); auto error = GetLastError(); if (error == ERROR_ACCESS_DENIED) { logError(L"Access was denied by process!", error); } else if (error != 0) { logError(L"Unknown error during remote thread creation", error); } return hRemoteHandle; }
static double prof_native_thread (size_t iteration) { #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_WTHREADS) || defined (ACE_HAS_STHREADS)) if (iteration != 0) { ACE_Profile_Timer ptimer; ACE_Profile_Timer::ACE_Elapsed_Time et; double time = 0; for (size_t i = 0; i < iteration; i++) { ACE_STOP_SIGN; ptimer.start (); for (size_t j = 0; j < MULTIPLY_FACTOR; j++) { #if defined (ACE_HAS_WTHREADS) if (::CreateThread (NULL, 0, LPTHREAD_START_ROUTINE (ace_empty), 0, CREATE_SUSPENDED, 0) == NULL) #elif defined (ACE_HAS_STHREADS) if (::thr_create (NULL, 0, &ace_empty, 0, THR_SUSPENDED, NULL) != 0) #endif ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CreateThread"), -1); } ptimer.stop (); ptimer.elapsed_time (et); time += et.real_time; } iteration *= MULTIPLY_FACTOR; return time / iteration; } else return -1.0; #else ACE_UNUSED_ARG (iteration); ACE_ERROR_RETURN ((LM_ERROR, "Testing of native threads is not supported on this platform.\n"), -1); #endif }
void DBWin::start() { if (!initialized) { std::cerr << "Not initialized" << std::endl; return; } if (hThread) { std::cerr << "Thread already running" << std::endl; return; } keepRunning = true; hThread = CreateThread(nullptr, 0, LPTHREAD_START_ROUTINE(run), this, 0, nullptr); }
// Main driver function for the server. int main (int argc, char *argv[]) { struct sockaddr_in sock_addr; // Handle UNIX/Win32 portability. #if defined (_WIN32) SOCKET acceptor; WORD version_requested = MAKEWORD(2,0); WSADATA wsa_data; int error = WSAStartup(version_requested, &wsa_data); if (error != 0) return -1; #else int acceptor; #endif /* _WIN32 */ // Create a local endpoint of communication. acceptor = socket (AF_INET,SOCK_STREAM, 0); // Set up the address to become a server. memset (&sock_addr, 0, sizeof(sock_addr)); sock_addr.sin_family = PF_INET; sock_addr.sin_port = htons(LOGGING_PORT); sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); // Associate address with endpoint. bind (acceptor,reinterpret_cast<struct sockaddr *>(&sock_addr), sizeof(sock_addr)); // Make endpoint listen for connections. listen (acceptor, 5); // Main server event loop. for (;;) { // Handle UNIX/Win32 portability. #if defined (_WIN32) SOCKET h; DWORD t_id; #else int h; thread_t t_id; #endif /* _WIN32 */ // Block waiting for clients to connect. h = accept (acceptor, 0, 0); //Spawn a new thread that runs the <server> entry point. #if defined (_WIN32) CreateThread (0, 0,LPTHREAD_START_ROUTINE(&logging_handler),reinterpret_cast <void *>(h), 0, &t_id); #else thr_create(0, 0, logging_handler,reinterpret_cast <void *> (h),THR_DETACHED, &t_id); #endif /* _WIN32 */ } return 0; }
void WatchDog::RunWatchDog(bool bNotice) { if (false == m_bOpenWatchDog) {//关闭看门狗 ClosedWatchDog(); return; } //看门狗已启动 if (m_hWatchDog) { return; } //启动看门狗 //第一个接口函数,传递心跳间隔 if(OpenWatchDog(6)) { //传递服务器所在pc的登陆用户名和密码,为自动重启所用 //if (!WriteAdminInfoToFileEX(m_chSysName, m_chSysPassWord)) //{ // AfxMessageBox(_T("用户信息保存失败!"), MB_OK | MB_ICONINFORMATION); //} //创建发送心跳的线程和控制线程退出的事件 DWORD dwRet; m_hCloseWatchDogEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_hWatchDog = CreateThread(NULL,0, LPTHREAD_START_ROUTINE (Thread_WatchDog_HeartBeat), (void*)this,0,&dwRet); LOG(LEVEL_INFO, "开启看门狗程序"); if (m_hWatchDog && bNotice) { AfxMessageBox(_T("启动看门狗成功!"), MB_ICONINFORMATION); } } else { AfxMessageBox(_T("启动看门狗失败!"),MB_ICONSTOP); } }
void CPlayer::OpenStream() { m_dwDisplayHour = 0; m_dwDisplayMinute = 0; m_dwDisplaySecond = 0; m_dwTotalFrames = 0; m_bFileEnd = FALSE; HIK_MEDIAINFO stInfo; ZeroMemory(&stInfo,sizeof(HIK_MEDIAINFO)); m_spStreamParser.reset(CStreamParseFactory::OpenFile(m_strPlayFileName)); if(m_spStreamParser.get() == NULL) { MessageBox(NULL, _T("Open file failed"), _T("Error"), MB_OK); throw 0; } m_dwMaxFileSize = m_spStreamParser->GetFileSize(); if (m_dwMaxFileSize == 0) { MessageBox(NULL, _T("Open file failed"), _T("Error"), MB_OK); throw 0; } NAME(PlayM4_SetStreamOpenMode)(m_index, STREAME_FILE); m_dwHeadSize = NAME(PlayM4_GetFileHeadLength)(); PBYTE pBuf = NULL; TCHAR szError[50]; pBuf = new BYTE[m_dwHeadSize]; if(!pBuf) { MessageBox(NULL, _T("Alloc memory failed"), _T("Error"), MB_OK); throw 0; } DWORD nRealRead = m_spStreamParser->ReadCacheData(pBuf, m_dwHeadSize); if(nRealRead != m_dwHeadSize) { MessageBox(NULL, _T("File is too small"), _T("Error"), MB_OK); delete []pBuf; pBuf = NULL; throw 0; } unsigned int g_strFileHdr[10] = { 0x484B4834, 0xd6d0b3fe, 0x20040308, 0x0, 0x10011001, 0x00101001, 0x3e80, 0x01200160, 0x1011, 0x4 }; #ifdef SPLIT_INPUT if(!NAME(PlayM4_OpenStreamEx)(m_lPort, (BYTE*)&stInfo, m_dwHeadSize, 6*1000*1024)) { _stprintf(szError, _T("Open stream failed(%s)"), MyErrorToString(NAME(PlayM4_GetLastError)(m_lPort))); MessageBox(csError); delete []pBuf; pBuf = NULL; throw 0; } PlayM4_SyncToAudio(m_lPort, FALSE); #else defined MIX_INPUT if(!NAME(PlayM4_OpenStream)(m_index, pBuf, sizeof(stInfo), 6*1000*1024)) { MessageBox(NULL, _T("Open file failed"), _T("Error"), MB_OK); delete []pBuf; pBuf = NULL; throw 0; } #endif delete []pBuf; pBuf = NULL; DWORD dw; m_hThread = NULL; m_hEventInput = NULL; m_hEventKill = NULL; ResizeMonitorWindow(); m_hThread = CreateThread(NULL,0, LPTHREAD_START_ROUTINE (InputStreamThread),this,0,&dw); m_hEventInput = CreateEvent(NULL,TRUE,FALSE,NULL); m_hEventKill = CreateEvent(NULL,FALSE,FALSE,NULL); if( !(m_hThread&&m_hEventInput&&m_hEventKill) ) { MessageBox(NULL, _T("Create thread failed"), _T("Error"), MB_OK); throw 0; } m_dwMaxFileTime = m_spStreamParser->GetLastFrameTime()-m_spStreamParser->GetFirstFrameTime(); m_dwStreamCurrentTime = 0; if(!m_dwMaxFileTime) { m_dwMaxFileTime = 1; } m_dwDisplayHour = m_dwMaxFileTime/3600; m_dwDisplayMinute = (m_dwMaxFileTime % 3600) / 60; m_dwDisplaySecond = m_dwMaxFileTime % 60; m_dwTotalFrames = m_dwMaxFileTime; Play(); }
HANDLE RunTranslationThread(HANDLE hFrom, HANDLE hTo) { PTRANSLATION_PARAMS params = new TRANSLATION_PARAMS; params->hFrom = hFrom; params->hTo = hTo; return CreateThread(NULL, 0, LPTHREAD_START_ROUTINE(&TranslationThread), params, 0, NULL); }
// ============================================================================ // // Criação da tread final // ============================================================================ // void Dll_Inject(){ CreateThread(NULL,NULL,LPTHREAD_START_ROUTINE(I_Scan),NULL,0,0); }