fork download
  1. #include <thread>
  2. #include <chrono>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. bool func(bool bFlag = false){
  8. cout<<"\t->func1"<<endl;
  9. return bFlag ;
  10. }
  11.  
  12. void proc(int * p){
  13. if( p )
  14. *p = 0;
  15. }
  16.  
  17. int calc(int a, int b) throw (const char *){
  18. if( b == 0 )
  19. throw "div on zero";
  20. return a / b;
  21. }
  22.  
  23.  
  24. int main(){
  25. volatile int p = 1;
  26. bool result = false;
  27. int * ptr = (int *)(&p);
  28. thread t(proc, ptr);
  29. try{
  30. if
  31. (
  32. (result = p != 0), t.detach(), this_thread::sleep_for (chrono::seconds(5)), result&&
  33. func(calc(1, p))
  34. )
  35. cout<<"true "<<endl;
  36. else
  37. cout<<"false"<<endl;
  38. }
  39. catch(const char * msg){
  40. cout<<msg<<endl;
  41. }
  42. cin.get();
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 11664KB
stdin
Standard input is empty
stdout
div on zero