Advertisement
Guest User

Untitled

a guest
Mar 24th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <queue>
  2. #include <future>
  3.  
  4. class ThreadManager {
  5. std::queue<std::function<void()>> _tasks;
  6.  
  7. public:
  8. template<class F>
  9. void futureTask(F&& f) {
  10. // the idea here is to package a task, and push it
  11. _tasks.push([] {});
  12. }
  13. };
  14.  
  15. class Runner {
  16. public:
  17.  
  18. Runner() {
  19. ThreadManager tm;
  20. auto runFn = std::bind(&Runner::run, this);
  21. tm.futureTask(std::move(runFn));
  22. }
  23.  
  24. void run() {
  25. // do some stuff
  26. }
  27. };
  28.  
  29. int main() {
  30. Runner r;
  31. r.run();
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement