fork(1) download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4.  
  5. struct Test
  6. {
  7. Test(int x_) : x ( x_)
  8. { std::cout << "constructor Test ( " << x << " )" << std::endl ; }
  9. ~Test()
  10. { std::cout << "destructor Test ( " << x << " )" << std::endl ; }
  11. int x ;
  12. } ;
  13.  
  14.  
  15. void bar ()
  16. {
  17. std::cout << "begin bar()" << std::endl ;
  18. thread_local Test obj ( 1 ) ;
  19. std::cout << "end bar()" << std::endl ;
  20. }
  21.  
  22. void foo ()
  23. {
  24. std::cout << "begin foo()" << std::endl ;
  25. static Test obj ( 0 ) ;
  26. bar() ;
  27. std::cout << "end foo()" << std::endl ;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. std::cout << "begin main()" << std::endl ;
  34. foo() ;
  35. std::cout << "end main()" << std::endl ;
  36. }
  37.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
begin main()
begin foo()
constructor Test ( 0 )
begin bar()
constructor Test ( 1 )
end bar()
end foo()
end main()
destructor Test ( 1 )
destructor Test ( 0 )