void killWorkerThread()
 {
     mRunThread = false;
     if ( mWorkerThread.joinable() )
     {
         mWorkerThread.join();
     }
 }
예제 #2
0
 ~ThreadRunner() noexcept
     try
 {
     g_quit = true;
     if (thread_.joinable()) thread_.join();
 } catch (std::exception& e) {
     cybozu::PutLog(cybozu::LogError, "ThreadRunner: error: %s", e.what());
 }
예제 #3
0
			~progressIndicatorThreadWrapper()
			{
				m_stopCondition.store( true );

				if( m_thread.joinable() )
				{
					m_thread.join();
				}
			}
예제 #4
0
  ~TetrisGame_impl()
  {
    if(runner.joinable())
      {
	gameOver();
	pauseCondition.notify_all();
	runner.join();
      }
  }
예제 #5
0
		void quit()
		{
			if (!_thread.joinable())
				return;
			_commandQueue.autoPriorityEmplace<TMQ::CloseQueue>();
			_run = false;
			_thread.join();
			_release();
		}
예제 #6
0
		void stop() noexcept
		{
			if( !th_.joinable() ) {
				return;
			}

			exit_flag_ = true;
			event_.set();
		}
예제 #7
0
파일: main.cpp 프로젝트: niklasf/k2
//--------------------------------
void QuitCommand(std::string in)
{
    UNUSED(in);
#ifdef USE_THREAD_FOR_INPUT
    if(busy || t.joinable())
        StopEngine();
#endif // USE_THREAD_FOR_INPUT

    quit = true;
}
예제 #8
0
	~Impl()
	{
		{
			std::unique_lock<std::mutex> lock(m_queueGuard);
			std::queue<Data>().swap(m_queue);
		}
		Stop();
		if (m_thread.joinable())
			m_thread.join();
	}
예제 #9
0
// 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();
	}
}
예제 #10
0
void HiresTexture::Shutdown()
{
  if (s_prefetcher.joinable())
  {
    s_textureCacheAbortLoading.Set();
    s_prefetcher.join();
  }

  s_textureMap.clear();
  s_textureCache.clear();
}
예제 #11
0
파일: Core.cpp 프로젝트: bullist/dolphin
void Shutdown()
{
	// During shutdown DXGI expects us to handle some messages on the UI thread.
	// Therefore we can't immediately block and wait for the emu thread to shut
	// down, so we join the emu thread as late as possible when the UI has already
	// shut down.
	// For more info read "DirectX Graphics Infrastructure (DXGI): Best Practices"
	// on MSDN.
	if (s_emu_thread.joinable())
		s_emu_thread.join();
}
예제 #12
0
파일: DVDThread.cpp 프로젝트: booto/dolphin
static void StopDVDThread()
{
  ASSERT(s_dvd_thread.joinable());

  // By setting s_DVD_thread_exiting, we ask the DVD thread to cleanly exit.
  // In case the request queue is empty, we need to set s_request_queue_expanded
  // so that the DVD thread will wake up and check s_DVD_thread_exiting.
  s_dvd_thread_exiting.Set();
  s_request_queue_expanded.Set();

  s_dvd_thread.join();
}
예제 #13
0
		void start(boost::string_ref dir, std::function< bool( boost::string_ref) >&& f)
		{
			if( th_.joinable() ) {
				return;
			}

			f_ = std::move( f );
			dir_ = winapi::directory_handle( dir, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED );
			exit_flag_ = false;

			th_ = std::thread( [this] { this->thread_main(); } );
		}
예제 #14
0
void vc4cl::initEventQueue()
{
    std::lock_guard<std::mutex> guard(queuesMutex);
    numCommandQueues++;
    if(!eventHandler.joinable())
    {
#ifdef DEBUG_MODE
        std::cout << "[VC4CL] Starting queue handler thread..." << std::endl;
#endif
        eventHandler = std::thread(runEventQueue);
    }
}
예제 #15
0
파일: Core.cpp 프로젝트: CarlKenner/dolphin
bool IsGPUThread()
{
  const SConfig& _CoreParameter = SConfig::GetInstance();
  if (_CoreParameter.bCPUThread)
  {
    return (s_emu_thread.joinable() && (s_emu_thread.get_id() == std::this_thread::get_id()));
  }
  else
  {
    return IsCPUThread();
  }
}
예제 #16
0
bool NTServerManager::StartProcessingPackets()
{
    static std::thread PacketThread;

    if (!PacketThread.joinable())
    {
        PacketThread = std::thread(PacketProcessingThread);
        PacketThread.detach();
        return true;
    }

    return false;
}
예제 #17
0
bool IsGPUThread()
{
	const SCoreStartupParameter& _CoreParameter =
		SConfig::GetInstance().m_LocalCoreStartupParameter;
	if (_CoreParameter.bCPUThread)
	{
		return (g_EmuThread.joinable() && (g_EmuThread.get_id() == std::this_thread::get_id()));
	}
	else
	{
		return IsCPUThread();
	}
}
예제 #18
0
  void run()
  {
    isPaused=false;
    if(!runner.joinable()) // Thread not yet initialized
      {
	timeCount=0;
	newPiece();
	isContinuing=true;
	runner = std::thread( &TetrisGame_impl::threadFunc, this);
      }
    
    pauseCondition.notify_one();
  }
예제 #19
0
파일: kmapi-jni.cpp 프로젝트: Jamol/kuma
void jni_fini()
{
    stop_loop = true;
    main_loop.stop();
    try {
        if (net_thread.joinable()) {
            net_thread.join();
        }
    }
    catch (...) {

    }
}
 void stop() {
     std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
     if (!is_running_) {
         return;
     }
     if (thread_.joinable()) {
         async([&]() {
             requires_stop_ = true;
         });
         thread_.join();
     }
     is_running_ = false;
 }
예제 #21
0
    /**
     * Close the task. This will raise in this thread any exception the
     * task generated in the other thread. Calling this function is
     * optional, because the destructor will also call this function.
     * But because it can throw an exception, it is better to call it
     * explicitly.
     */
    void close() {
        // If an exception happened in the task, re-throw
        // it in this thread. This will block if the task
        // isn't finished.
        if (m_future.valid()) {
            m_future.get();
        }

        // Make sure task is done.
        if (m_thread.joinable()) {
            m_thread.join();
        }
    }
예제 #22
0
파일: main.cpp 프로젝트: niklasf/k2
//--------------------------------
int main(int argc, char* argv[])
{
    UNUSED(argc);
    UNUSED(argv);

#ifdef TUNE_PARAMETERS
    for(int i = 0; i < NPARAMS; ++i)
        param.push_back(1);
#endif
    InitEngine();
    tt.clear();

    max_search_depth      = max_ply;
    time_remains     = 300000000;
    time_base        = 300000000;
    time_inc         = 0;
    moves_per_session = 0;
    max_nodes_to_search    = 0;
    time_command_sent = false;

    char in[0x4000];
    while(!quit)
   {
        if(!std::cin.getline(in, sizeof(in), '\n'))
            std::cin.clear();

        if(CmdProcess((std::string)in))
        {
            // NiCheGoNeDeLaYem!
        }
        else if(!busy && LooksLikeMove((std::string)in))
        {
            if(!MakeMoveFinaly(in))
                std::cout << "Illegal move" << std::endl;
            else if(!force)
            {
#ifdef USE_THREAD_FOR_INPUT
                if(t.joinable())
                    t.join();
                t = std::thread(MainSearch);
#else
                MainSearch();
#endif // USE_THREAD_FOR_INPUT
            }
        }
        else
            std::cout << "Unknown command: " << in << std::endl;
    }
    if(busy)
        StopEngine();
}
예제 #23
0
파일: main.cpp 프로젝트: niklasf/k2
//--------------------------------
void AnalyzeCommand(std::string in)
{
    UNUSED(in);
    force = false;
    infinite_analyze = true;

    #ifdef USE_THREAD_FOR_INPUT
    if(t.joinable())
        t.join();
    t = std::thread(MainSearch);
    #else
    MainSearch();
    #endif // USE_THREAD_FOR_INPUT
}
예제 #24
0
파일: Source.cpp 프로젝트: Sir2B/Uni
void TimeoutFunction(const char* MyString)
{
	printf("Startet %s\n", MyString);
	StartTime = GetTickCount();
	PrintString = MyString;
	running = false;
	if (InternThread.joinable())
	{
		InternThread.join();
	}

	running = true;
	InternThread = std::thread(MyPrint);
}
예제 #25
0
void vc4cl::deinitEventQueue()
{
    std::lock_guard<std::mutex> guard(queuesMutex);
    numCommandQueues--;
    if(numCommandQueues == 0 && eventHandler.joinable())
    {
#ifdef DEBUG_MODE
        std::cout << "[VC4CL] Stopping queue handler thread..." << std::endl;
#endif
        // wake up event handler, so we can stop it
        eventAvailable.notify_all();
        eventHandler.join();
    }
}
예제 #26
0
void peterDeJongSetup( ) {

    // std::cout << "DeJong parameters: " << a << ", " << b << ", " << c << ", " << d << std::endl;

    shouldRun = false;
    if( updater.joinable( ) )
        updater.join( );

    for( int i = 0; i < height * width; ++i )
        image[ i ] = 0.0;

    shouldRun = true;
    updater = std::thread( peterDeJongFun );

}
예제 #27
0
파일: login.cpp 프로젝트: Scavenge/darkstar
void do_final(int code)
{
    message_server_close();
    if (messageThread.joinable())
    {
        messageThread.join();
    }

    Sql_Free(SqlHandle);

    timer_final();
    socket_final();

    exit(code);
}
예제 #28
0
파일: Main.cpp 프로젝트: iSLC/VCMP-Announce
/* ------------------------------------------------------------------------------------------------
 * The server was shutdown and this plug-in must terminate as well.
*/
static void OnServerShutdown(void)
{
    // The server may still send callbacks
    _Clbk->OnServerInitialise       = nullptr;
    _Clbk->OnServerShutdown         = nullptr;
    _Clbk->OnServerFrame            = nullptr;
    // Tell the announce thread to stop
    g_Announce = false;
    // Wait for the announce thread to finish
    if (g_Thread.joinable())
    {
        g_Thread.join();
    }
    // Flush any remaining messages
    FlushMessages();
}
예제 #29
0
파일: main.cpp 프로젝트: niklasf/k2
//--------------------------------
void GoCommand(std::string in)
{
    UNUSED(in);
    if(busy)
        return;

    if(uci)
        UciGoCommand(in);
    else
        force = false;
#ifdef USE_THREAD_FOR_INPUT
    if(t.joinable())
        t.join();
    t = std::thread(MainSearch);
#else
    MainSearch();
#endif // USE_THREAD_FOR_INPUT

}
예제 #30
0
// This is called from the GUI thread. See the booting call schedule in
// BootManager.cpp
bool Init()
{
	const SCoreStartupParameter& _CoreParameter =
		SConfig::GetInstance().m_LocalCoreStartupParameter;

	if (s_emu_thread.joinable())
	{
		if (IsRunning())
		{
			PanicAlertT("Emu Thread already running");
			return false;
		}

		// The Emu Thread was stopped, synchronize with it.
		s_emu_thread.join();
	}

	Core::UpdateWantDeterminism(/*initial*/ true);

	INFO_LOG(OSREPORT, "Starting core = %s mode",
		_CoreParameter.bWii ? "Wii" : "GameCube");
	INFO_LOG(OSREPORT, "CPU Thread separate = %s",
		_CoreParameter.bCPUThread ? "Yes" : "No");

	Host_UpdateMainFrame(); // Disable any menus or buttons at boot

	g_aspect_wide = _CoreParameter.bWii;
	if (g_aspect_wide)
	{
		IniFile gameIni = _CoreParameter.LoadGameIni();
		gameIni.GetOrCreateSection("Wii")->Get("Widescreen", &g_aspect_wide,
		     !!SConfig::GetInstance().m_SYSCONF->GetData<u8>("IPL.AR"));
	}

	s_window_handle = Host_GetRenderHandle();

	// Start the emu thread
	s_emu_thread = std::thread(EmuThread);

	return true;
}