fork download
  1. #include <iostream>
  2. #include <thread>
  3. #include <pthread.h>
  4.  
  5. void foo(int a)
  6. {
  7. char name[255]={0};
  8. // Weisen Sie dem Thread einen Namen zu
  9. if(pthread_setname_np(pthread_self(), "JoesThread")) {
  10. std::cerr << "Fehler beim Zuweisen des Namens" << std::endl;
  11. }
  12. // int pthread_getname_np(pthread_t thread, char name[.size], size_t size);
  13. if(pthread_getname_np(pthread_self(), name, 255)) {
  14. std::cerr << "Fehler beim Zuweisen des Namens" << std::endl;
  15. }
  16. std::cout << "Joe: " << name << '\n';
  17. }
  18.  
  19. int main()
  20. {
  21. // Create and execute the thread
  22. std::thread thread{ foo, 10 }; // Pass 10 to free function
  23.  
  24. // The free function will be executed in a separate thread
  25.  
  26. // Wait for the thread to finish, this is a blocking operation
  27. thread.join();
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Joe: JoesThread