• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "boost/atomic.hpp"
2 #include "boost/thread.hpp"
3 #include <iostream>
4 
5 using namespace boost;
6 
main()7 int main() {
8     atomic<size_t> total(0), failures(0);
9 
10 #pragma omp parallel shared(total, failures) num_threads(1000)
11     {
12       mutex mtx;
13       condition_variable cond;
14       unique_lock<mutex> lk(mtx);
15       for (int i = 0; i < 500; i++) {
16         ++total;
17         if (cv_status::timeout != cond.wait_for(lk, chrono::milliseconds(10)))
18           ++failures;
19       }
20     }
21     if(failures)
22       std::cout << "There were " << failures << " failures out of " << total << " timed waits." << std::endl;
23     if((100*failures)/total>40)
24     {
25       std::cerr << "This exceeds 10%, so failing the test." << std::endl;
26       return 1;
27     }
28     return 0;
29 }
30