virtual void TearDown() { // If a thread has not completed, then continuing will cause the tests to // hang forever and could cause issues. If we don't call detach, then // std::terminate is called and all threads are terminated. // Detaching is non-optimal, but should allow the rest of the tests to run // before anything drastic occurs. if (m_done1) m_watcher1.join(); else m_watcher1.detach(); if (m_done2) m_watcher2.join(); else m_watcher2.detach(); }
/* * \brief Close a fd * * \param void */ BJBPErr_t NetworkServer::open(uint32_t ipAddr, uint32_t port) { struct sockaddr_in server; //Create socket m_fd = socket(AF_INET , SOCK_STREAM , 0); if (m_fd < 0) { BJBP_LOG_ERR("Unable to create a Network Server socket\n"); return BJBP_ERR_OPEN_FD; } //Prepare the sockaddr_in structure server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons( DEFAULT_NETWORK_SERVER_PORT ); //Bind if( bind(m_fd,(struct sockaddr *)&server , sizeof(server)) < 0) { BJBP_LOG_ERR("Unable to bind to the Network Server socket. Err msg: %s\n", errno); return BJBP_ERR_BIND; } //Listen listen(m_fd , SERVER_MAX_NUM_PENDING_CLIENTS); // Start the server static std::thread serverThread = std::thread(&NetworkServer::serverListenerThread, this); serverThread.detach(); m_running = true; return BJBP_SUCCESS; }
void Graphics::init(GLFWwindow* aWindowHandle) { s_Window = aWindowHandle; Debug::announce("Engine init: Graphics initializing..."); printf("Graphics::Graphics()\n"); GLHelp::Diagnostics::clearGLErrors(); ////Load static defaults s_ShaderPrograms.init(); s_Textures.init(); s_RenderTextures.init(); s_Models.init(); //Load dynamic autos s_ShaderPrograms.loadDirectory ("../Shaders" ); s_Textures.loadDirectory ("../Textures"); s_Models.loadDirectory ("../Models" ); glfwSetWindowSizeCallback(aWindowHandle, windowSizeCallback); glfwSetWindowSize(aWindowHandle, s_WindowSize.x, s_WindowSize.y); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glfwSetFramebufferSizeCallback(s_Window, frameBufferResizeCallBack); //init thread glfwMakeContextCurrent(0); //relinquish control of context, graphics will pick this up s_RenderThread = std::thread(renderThreadDrawLoop); s_RenderThread.detach(); }
bool lConsole::Initialize(void *FileHandle, void *Stream, uint32_t ScreenbufferSize) { // Allocate a console if we don't have one. if (!strstr(GetCommandLineA(), "-nocon")) { AllocConsole(); // Take ownership of it. AttachConsole(GetCurrentProcessId()); // Set the standard streams to use the console. freopen("CONOUT$", "w", (FILE *)Stream); // Start the update thread. if (!UpdateThread.joinable()) { UpdateThread = std::thread(&lConsole::Int_UpdateThread, this); UpdateThread.detach(); } } // Fill our properties. ThreadSafe.lock(); this->FileHandle = FileHandle; this->StreamHandle = Stream; this->ShouldPrintScrollback = ScreenbufferSize != 0; this->StartupTimestamp = GetTickCount64(); this->LastTimestamp = this->StartupTimestamp; this->ScrollbackLineCount = ScreenbufferSize; this->ScrollbackLines = new lLine[this->ScrollbackLineCount](); this->ProgressbarCount = 0; ThreadSafe.unlock(); return true; }
void dbus_initialize(void) { DBusError err; dbus_threads_init_default(); dbus_error_init(&err); if (!(service_bus = dbus_connection_open(SERVICE_BUS_ADDRESS, &err))) { dbus_error_free(&err); errx(1, "failed to connect to service bus: %s: %s", err.name, err.message); } if (!dbus_bus_register(service_bus, &err)) { dbus_error_free(&err); errx(1, "failed to register with service bus: %s: %s", err.name, err.message); } dbus_error_free(&err); service_thread = std::thread([]() { // dispatch messages until disconnect while (dbus_connection_read_write_dispatch(service_bus, -1)); dbus_connection_unref(service_bus); }); service_thread.detach(); }
void try_connect() { bool f = false; if (!connecting.compare_exchange_strong(f, true)) return; connector.swap(std::thread(std::bind(&transport_t::thread_connect, this))); connector.detach(); return; }
// Helper function for cleaning up the thread in use inline void cleanupThread(std::thread &t) { if (t.joinable()) { t.join(); } else if (t.get_id() != std::thread::id()) { t.detach(); } }
bool NTServerManager::StartProcessingPackets() { static std::thread PacketThread; if (!PacketThread.joinable()) { PacketThread = std::thread(PacketProcessingThread); PacketThread.detach(); return true; } return false; }
std::future<void> Promise(size_t index) { assert(std::try_lock(m_workerMutex) == 0); // expects outside lock m_promises.emplace_back(index, std::promise<void>()); if (m_bWorkerInactive) { // restart worker thread if needed m_worker.detach(); m_worker = std::thread(std::bind(&QuviSimpleStreamBackend::Loop, this)); m_bWorkerInactive = false; } return m_promises.back().second.get_future(); }
void simulateNetworkError() { errorSimulatorThread.detach(); while (true) { usleep(kSimulatorSleepDurationMillis * 1000); auto &options = facebook::wdt::WdtOptions::getMutable(); int fd = 3 + rand32() % (2 * options.num_ports + 1); // close the chosen socket if (shutdown(fd, SHUT_WR) < 0) { PLOG(WARNING) << "socket shutdown failed for fd " << fd; } else { WLOG(INFO) << "successfully shut down socket for fd " << fd; } } }
void Dispatcher::Initialize() { inited = true; subscriberQueue = new std::list<Subscriber*>(); dispatchEvents = new std::vector<std::pair<double,void*>>(); mappedEvents = new std::map<int,std::list<Subscriber*>*>(); running = true; processing = true; dispatchLock = false; mappedLock = false; subscriberLock = false; localDeltaTime = (double*)0; processingThread = std::thread(Process, localDeltaTime); //starts the processing thread processingThread.detach(); //it probably won't terminate before the end of this program so we want to ignor errors }
~Timeout() { if(my_Worker.joinable()) my_Worker.detach(); }
int main(int argc, const char* argv[]) { #ifdef _WIN32 //Start up Winsock… WSADATA wsadata; int error = WSAStartup(0x0202, &wsadata); if (error) //Did something happen? { std::cerr<<"Unable to start winsock"<<std::endl; return -1; } if (wsadata.wVersion != 0x0202)//Did we get the right Winsock version? { Die("version mismatch"); } #endif std::cout << "Enter Server URL: "; char url[0x100]; std::cin.getline(url,sizeof(url)); std::cout << "Enter your Nickname: "; char nickname[0x100] = ":"; std::cin.getline(nickname+1,sizeof(nickname)-1); char*colon = strchr(url,':'); std::string surl,sport; if (colon != NULL) { *colon = 0; sport = colon+1; } else { sport = ToString(DEFAULT_PORT); } surl = url; PrintLine("Attempting to connect to "+surl); ADDRINFOA hints; memset(&hints,0,sizeof(hints)); hints.ai_protocol = IPPROTO_TCP; hints.ai_family = AF_UNSPEC; //hints. ADDRINFOA*result; if (getaddrinfo(surl.c_str(),sport.c_str(),&hints,&result) != 0) { Die("Call to getaddrinfo() failed"); } bool connected = false; while (result) //search through all available results until one allows connection. //Chances are we get IPv4 and IPv6 results here but the server will only answer to one of those { sock = socket(result->ai_family,result->ai_socktype,result->ai_protocol); if (sock != INVALID_SOCKET) //if we can create a socket then we can attempt a connection. It would be rather unusual for this not to work but... { if (!connect(sock,result->ai_addr,result->ai_addrlen)) //attempt connnection { //connected PrintLine("Connected to "+ToString(*result)); //yay, it worked connected = true; break; } else { closesocket(sock); //these aren't the droids we're looking for. sock = INVALID_SOCKET; } } result = result->ai_next; //moving on. } if (!connected) Die("Failed to connect to "+surl+":"+sport); //so, yeah, none of them worked. Submit(nickname); //includes leading ':', so that the server knows this is a name, not a message netThread = std::thread(NetLoop); //start read-thread while (sock != INVALID_SOCKET) { char c = _getch(); //keep reading characters { if (c == 3) //this only works on windows, but ctrl-c is handled better on linux anyway { Die("Ctrl+C"); break; } consoleLock.lock(); if (c == '\n' || c == '\r') //user pressed enter/return: { std::string submit = inputBuffer; //copy buffer to string std::cout << '\r'; //move cursor to line beginning for (size_t i = 0; i < inputBufferUsage+1; i++) //overwrite line with as many blanks as there were characters std::cout << ' '; std::cout << '\r'; //move cursor to line beginning again inputBufferUsage = 0; //reset character pointer inputBuffer[0] = 0; //write terminating zero to first char consoleLock.unlock(); //release console lock Submit(submit); //process input } else { if (c == Backspace) //user pressed backspace { if (inputBufferUsage > 0) { inputBuffer[--inputBufferUsage] = 0; //decrement character pointer and overwrite with 0 std::cout << '\r'<<':'<<inputBuffer<<" \r"<<':'<<inputBuffer; } } else { if (c == '!' || c == '?' || ( c != -32 && (isalnum(c) || c == ' '))) //ordinary character { if (inputBufferUsage+1 < maxInputBufferUsage) //only allow up to 255 characters though { inputBuffer[inputBufferUsage++] = c; //write to the end of the buffer inputBuffer[inputBufferUsage] = 0; //and terminate properly } std::cout << c; //update console } } consoleLock.unlock(); } } } netThread.join(); netThread.detach(); netThread.swap(std::thread()); #ifdef _WIN32 WSACleanup(); #endif return 0; }
void PPU_dispose() { PPU_thread_exit = true; PPU_thread.detach(); delete[] VRAM; delete[] OAM; }
void detach() { internal_thread.detach(); }
NetworkThread() : m_work(m_service), m_pendingShutdown(false), m_serviceThread([this] { boost::system::error_code ec; this->m_service.run(ec); }), m_socketCleanupThread([this] { this->SocketCleanupWork(); }) { m_serviceThread.detach(); }
void detach() { t_.detach(); }