Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include "tbb/compat/thread"
  3. #include "tbb/pipeline.h"
  4.  
  5. using namespace tbb;
  6. using namespace std;
  7.  
  8. char InputString[] = "abcdefgn";
  9.  
  10. class InputFilter: public thread_bound_filter {
  11. char* my_ptr;
  12. public:
  13. void* operator()(void*) {
  14. if (*my_ptr)
  15. return my_ptr++;
  16. else
  17. return NULL;
  18. }
  19. InputFilter()
  20. : thread_bound_filter( serial_in_order ), my_ptr(InputString)
  21. {}
  22. };
  23.  
  24. class OutputFilter: public filter {
  25. public:
  26. void* operator()(void* item) {
  27. std::cout << *(char*)item;
  28. return NULL;
  29. }
  30. OutputFilter() : filter(serial_in_order) {}
  31. };
  32.  
  33. void RunPipeline(pipeline* p) {
  34. p->run(8);
  35. }
  36.  
  37. int main() {
  38. // Construct the pipeline
  39. InputFilter f;
  40. OutputFilter g;
  41. pipeline p;
  42. p.add_filter(f);
  43. p.add_filter(g);
  44.  
  45. // Another thread initiates execution of the pipeline
  46. thread t(RunPipeline, &p);
  47.  
  48. // Process the thread_bound_filter with the current thread.
  49. while (f.process_item()!=thread_bound_filter::end_of_stream)
  50. continue;
  51.  
  52. // Wait for pipeline to finish on the other thread.
  53. t.join();
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement