本文整理汇总了C++中std::thread::detach方法的典型用法代码示例。如果您正苦于以下问题:C++ thread::detach方法的具体用法?C++ thread::detach怎么用?C++ thread::detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::thread
的用法示例。
在下文中一共展示了thread::detach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TearDown
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();
}
示例2: open
/*
* \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;
}
示例3: init
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();
}
示例4: Initialize
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;
}
示例5: dbus_initialize
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();
}
示例6: try_connect
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;
}
示例7: cleanupThread
// 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();
}
}
示例8: StartProcessingPackets
bool NTServerManager::StartProcessingPackets()
{
static std::thread PacketThread;
if (!PacketThread.joinable())
{
PacketThread = std::thread(PacketProcessingThread);
PacketThread.detach();
return true;
}
return false;
}
示例9: Promise
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();
}
示例10: simulateNetworkError
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;
}
}
}
示例11: Initialize
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
}
示例12:
~Timeout() {
if(my_Worker.joinable())
my_Worker.detach();
}
示例13: main
//.........这里部分代码省略.........
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;
}
示例14: PPU_dispose
void PPU_dispose() {
PPU_thread_exit = true;
PPU_thread.detach();
delete[] VRAM;
delete[] OAM;
}
示例15: detach
void detach() { internal_thread.detach(); }