Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // (C) Copyright 2009-2012 Anthony Williams Chris@16: // (C) Copyright 2012 Vicente J. Botet Escriba Chris@16: Chris@16: // Based on the Anthony's idea of thread_joiner in CCiA Chris@16: Chris@16: #ifndef BOOST_THREAD_THREAD_GUARD_HPP Chris@16: #define BOOST_THREAD_THREAD_GUARD_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: /** Chris@16: * Non-copyable RAII scoped thread guard joiner which join the thread if joinable when destroyed. Chris@16: */ Chris@16: template Chris@16: class thread_guard Chris@16: { Chris@16: thread& t_; Chris@16: public: Chris@16: BOOST_THREAD_NO_COPYABLE( thread_guard) Chris@16: Chris@16: explicit thread_guard(thread& t) : Chris@16: t_(t) Chris@16: { Chris@16: } Chris@16: ~thread_guard() Chris@16: { Chris@16: CallableThread on_destructor; Chris@16: Chris@16: on_destructor(t_); Chris@16: } Chris@16: }; Chris@16: Chris@16: } Chris@16: #include Chris@16: Chris@16: #endif