void shutdown()
{
  boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
  // gracefully return if we've not fired ros up yet, or mid-shutdown
  if (g_shutting_down || !g_initialized)
  {
    return;
  }

  ROSCPP_LOG_DEBUG("Shutting down roscpp");

  g_shutting_down = true;

  g_global_queue->disable();
  g_global_queue->clear();

  if (g_internal_queue_thread.get_id() != boost::this_thread::get_id())
  {
    g_internal_queue_thread.join();
  }

  const log4cxx::LoggerPtr& logger = log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME);
  logger->removeAppender(g_rosout_appender);
  g_rosout_appender = 0;

  // reset this so that the logger doesn't get crashily destroyed
  // again during global destruction.  
  //
  // See https://code.ros.org/trac/ros/ticket/3271
  //
  log4cxx::Logger::getRootLogger()->getLoggerRepository()->shutdown();
  log4cxx::LoggerPtr& fo_logger = ros::file_log::getFileOnlyLogger();
  fo_logger = log4cxx::LoggerPtr();
  
  if (g_started)
  {
    TopicManager::instance()->shutdown();
    ServiceManager::instance()->shutdown();
    PollManager::instance()->shutdown();
    ConnectionManager::instance()->shutdown();
    XMLRPCManager::instance()->shutdown();
  }

  WallTime end = WallTime::now();

  ROSCPP_LOG_DEBUG("Shutdown finished");

  g_started = false;
  g_ok = false;
  Time::shutdown();
}
Example #2
0
void nuke_ms::clientnode::catchThread(boost::thread& thread, unsigned threadwait_ms)
{
    // a thread id that compares equal to "not-a-thread"
    boost::thread::id not_a_thread;

    try {
        // give the thread a few seconds time to join
        thread.timed_join(boost::posix_time::millisec(threadwait_ms));
    }
    catch(...)
    {}

    // if the thread finished, return. otherwise try to kill the thread
    if (thread.get_id() == not_a_thread)
        return;

    thread.interrupt();

    // if it is still running, let it go
    if (thread.get_id() == not_a_thread)
        return;

    thread.detach();
}
Example #3
0
	// --------------------------------------------------------------
	/// This object's thread ID, or Not-any-thread if the thread is not running.
	/// @return - if this object refers to a thread of execution, an
	/// instance of boost::thread::id that represents this thread is
	/// returned. Otherwise, a default-constructed boost::thread::id
	/// is returned (and if you insert it into a stream, 
	/// you'll get '{Not-any-thread}').
	boost::thread::id id() const {
		return _thread.get_id();
	}
 string GetThreadID(){
     return Conv::ToString(m_Thread.get_id());
 }