fork download
  1. #include <tbb/tbb.h>
  2.  
  3. #include <iostream>
  4.  
  5. tbb::atomic<bool> caused_exception; // we want to cause an exception only once
  6.  
  7. struct seh_exception {};
  8.  
  9. void sehExceptionTranslator(unsigned int code, struct _EXCEPTION_POINTERS *ep)
  10. {
  11. throw seh_exception();
  12. }
  13.  
  14. void causeSehException()
  15. {
  16. // ensure that we have an exception translator even in sub_tasks
  17. _set_se_translator(sehExceptionTranslator);
  18.  
  19. // cause the exception exactly once
  20. if (!caused_exception.compare_and_swap(true, false))
  21. {
  22. volatile int *pInt = 0x00000000;
  23. *pInt = 20;
  24. }
  25. }
  26.  
  27. void causeSehExceptionInTbbThread()
  28. {
  29. tbb::parallel_for(0, 8, [&](int i)
  30. {
  31. tbb::this_tbb_thread::sleep(tbb::tick_count::interval_t( 0.5 ));
  32. causeSehException();
  33. });
  34. }
  35.  
  36. int main()
  37. {
  38. caused_exception = false;
  39.  
  40. _set_se_translator(sehExceptionTranslator);
  41. try
  42. {
  43. causeSehExceptionInTbbThread();
  44. }
  45. catch (seh_exception&)
  46. {
  47. std::cout << "seh exception caught" << std::endl;
  48. }
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:21: fatal error: tbb/tbb.h: No such file or directory
 #include <tbb/tbb.h>
                     ^
compilation terminated.
stdout

Standard output is empty