| 20 | static std::atomic<int> total; |
| 21 | |
| 22 | void *ThreadMain(void *arg) { |
| 23 | for (int i = 0; i < TOTAL; i++) { |
| 24 | try { |
| 25 | // Throw two different types, to make sure we check throwing and landing |
| 26 | // pad behavior. |
| 27 | if (i & 3) { |
| 28 | throw 3.14159f; |
| 29 | } |
| 30 | throw i; |
| 31 | } catch (int x) { |
| 32 | total += x; |
| 33 | } catch (float f) { |
| 34 | // wait for a change, so we see interleaved processing. |
| 35 | int last = ++sum; |
| 36 | while (sum.load() == last) {} |
| 37 | } |
| 38 | } |
| 39 | pthread_exit((void*)TOTAL); |
| 40 | } |
| 41 | |
| 42 | pthread_t thread[NUM_THREADS]; |
| 43 |