worker_thread.hpp
Go to the documentation of this file.
1 
17 #ifndef THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
18 #define THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
19 
20 
21 #include "scope_guard.hpp"
22 
23 #include <boost/smart_ptr.hpp>
24 #include <boost/thread.hpp>
25 #include <boost/thread/exceptions.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/bind.hpp>
28 
29 
30 namespace boost { namespace threadpool { namespace detail
31 {
32 
43  template <typename Pool>
45  : public enable_shared_from_this< worker_thread<Pool> >
46  , private noncopyable
47  {
48  public:
49  typedef Pool pool_type;
50 
51  private:
54 
55 
61  : m_pool(pool)
62  {
63  assert(pool);
64  }
65 
66 
70  {
71  m_pool->worker_died_unexpectedly(this->shared_from_this());
72  }
73 
74 
75  public:
78  void run()
79  {
80  scope_guard notify_exception(bind(&worker_thread::died_unexpectedly, this));
81 
82  while(m_pool->execute_task()) {}
83 
84  notify_exception.disable();
85  m_pool->worker_destructed(this->shared_from_this());
86  }
87 
88 
91  void join()
92  {
93  m_thread->join();
94  }
95 
96 
101  {
102  shared_ptr<worker_thread> worker(new worker_thread(pool));
103  if(worker)
104  {
105  worker->m_thread.reset(new boost::thread(bind(&worker_thread::run, worker)));
106  }
107  }
108 
109  };
110 
111 
112 } } } // namespace boost::threadpool::detail
113 
114 #endif // THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
115 
The namespace threadpool contains a thread pool and related utility classes.
shared_ptr< boost::thread > m_thread
Pointer to the thread which executes the run loop.
Pool pool_type
Indicates the pool&#39;s type.
worker_thread(shared_ptr< pool_type > const &pool)
static void create_and_attach(shared_ptr< pool_type > const &pool)
shared_ptr< pool_type > m_pool
Pointer to the pool which created the worker.


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Mon Dec 16 2019 03:31:15