fork download
  1. #include <iostream>
  2. #include <pthread.h>
  3.  
  4. class Example {
  5. public:
  6. Example () : thread_() {
  7. int rcode = pthread_create(&thread_, nullptr, Example::task, nullptr);
  8. if (rcode != 0) {
  9. std::cout << "pthread_create failed. Return code: " << rcode << std::endl;
  10. }
  11. }
  12.  
  13. static void * task (void *) {
  14. std::cout << "Running task." << std::endl;
  15. return nullptr;
  16. }
  17.  
  18. private:
  19. pthread_t thread_;
  20. };
  21.  
  22. int main () {
  23. Example example;
  24. }
  25.  
Success #stdin #stdout 0s 11648KB
stdin
Standard input is empty
stdout
Standard output is empty