GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
pool.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_NATIVE_POOL_H
22 #define GRPPI_NATIVE_POOL_H
23 
24 #include <boost/asio/io_service.hpp>
25 #include <boost/bind.hpp>
26 #include <boost/thread/thread.hpp>
27 
28 namespace grppi {
29 
31 {
32  private:
33  boost::thread_group threadpool;
34  boost::asio::io_service ioService;
35  std::vector<boost::asio::io_service::work> works;//(ioService);
36  int busy_threads= 0;
37 
38  public:
40  };
41 
42  template <typename T>
43  void create_task(T task ) { ioService.post(task); }
44 
45  void initialise (int num_threads) {
46  works.push_back( std::move(boost::asio::io_service::work(ioService)));
47  for(unsigned int nthr= 0; nthr < num_threads; nthr++){
48  threadpool.create_thread(
49  boost::bind(&boost::asio::io_service::run, &ioService)
50  );
51  }
52  };
53 
55  ioService.stop();
56  threadpool.join_all();
57  };
58 
59 };
60 
61 }
62 
63 #endif
Definition: callable_traits.h:24
void initialise(int num_threads)
Definition: pool.h:45
void create_task(T task)
Definition: pool.h:43
~thread_pool()
Definition: pool.h:54
thread_pool()
Definition: pool.h:39
Definition: pool.h:30