posix_sigwait.cpp 741 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include<__vic/posix/thread.h>
  2. #include<__vic/posix/sigset.h>
  3. #include<iostream>
  4. #include<exception>
  5. #include<cassert>
  6. #include<csignal>
  7. void run_tests()
  8. {
  9. #if __cpp_initializer_lists
  10. __vic::posix::sigset set{ SIGINT };
  11. #else
  12. __vic::posix::sigset set = __vic::posix::sigset::empty() << SIGINT;
  13. #endif
  14. __vic::posix::this_thread::block_signals(set);
  15. std::raise(SIGINT);
  16. std::cout << "Catching SIGINT... " << std::flush;
  17. int sig = __vic::posix::this_thread::sigwait(set);
  18. std::cout << "Caught!" << std::endl;
  19. assert(sig == SIGINT);
  20. }
  21. int main()
  22. {
  23. try
  24. {
  25. run_tests();
  26. return 0;
  27. }
  28. catch(const std::exception &ex)
  29. {
  30. std::cerr << ex.what() << '\n';
  31. }
  32. return 1;
  33. }