source:
CIVL/examples/pthread/esbmc/fib_bench_false.c@
dccd621
| Last change on this file since dccd621 was 27ff0f4, checked in by , 11 years ago | |
|---|---|
|
|
| File size: 526 bytes | |
| Rev | Line | |
|---|---|---|
| [16d81051] | 1 | //Race condition: fixed with pthread_join's at bottom |
| [09bc145] | 2 | #include <pthread.h> |
| 3 | ||
| 4 | int i=1, j=1; | |
| 5 | ||
| 6 | #define NUM 5 | |
| 7 | ||
| 8 | void * | |
| 9 | t1(void* arg) | |
| 10 | { | |
| 11 | int k = 0; | |
| 12 | ||
| 13 | for (k = 0; k < NUM; k++) | |
| 14 | i+=j; | |
| 15 | ||
| 16 | pthread_exit(NULL); | |
| 17 | } | |
| 18 | ||
| 19 | void * | |
| 20 | t2(void* arg) | |
| 21 | { | |
| 22 | int k = 0; | |
| 23 | ||
| 24 | for (k = 0; k < NUM; k++) | |
| 25 | j+=i; | |
| 26 | ||
| 27 | pthread_exit(NULL); | |
| 28 | } | |
| 29 | ||
| 30 | int | |
| 31 | main(int argc, char **argv) | |
| 32 | { | |
| 33 | pthread_t id1, id2; | |
| 34 | ||
| 35 | pthread_create(&id1, NULL, t1, NULL); | |
| [f97431f] | 36 | pthread_create(&id2, NULL, t2, NULL); |
| [16d81051] | 37 | |
| [09bc145] | 38 | if (i >= 144 || j >= 144) { |
| 39 | ERROR: | |
| 40 | goto ERROR; | |
| 41 | } | |
| [9e44c01] | 42 | |
| [09bc145] | 43 | return 0; |
| 44 | } |
Note:
See TracBrowser
for help on using the repository browser.
