fork(3) download
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4. #include <thread>
  5. using namespace std;
  6.  
  7. class bar
  8. {
  9. private:
  10. std::queue<std::string> lines; // The queue
  11. std::thread writer;
  12.  
  13. void write() // The function we call from thread
  14. {
  15. std::cout << "Hello world from other thread";
  16. }
  17. public:
  18. bar() : writer{&bar::write, this} {}
  19.  
  20. ~bar()
  21. {
  22. writer.join();
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. bar testing;
  29. std::cout << "Hello World from main thread" << std::endl;
  30.  
  31. /*
  32.   What this does is it allows me to keep the console open till we get a enter key.
  33.   */
  34.  
  35. // std::cin.clear();
  36. // std::cin.ignore(32767, '\n');
  37. // std::cin.get();
  38.  
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 11656KB
stdin
Standard input is empty
stdout
Hello World from main thread
Hello world from other thread