1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <stdlib.h>
|
|---|
| 2 | #include <pthread.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | void __VERIFIER_assert(int expression) { if (!expression) { ERROR: goto ERROR; }; return; }
|
|---|
| 6 |
|
|---|
| 7 | const int SIGMA = 16;
|
|---|
| 8 |
|
|---|
| 9 | int *array;
|
|---|
| 10 | int array_index = -1;
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | void *thread(void * arg)
|
|---|
| 14 | {
|
|---|
| 15 | array[array_index] = 1;
|
|---|
| 16 | return 0;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | int main()
|
|---|
| 21 | {
|
|---|
| 22 | int tid, sum;
|
|---|
| 23 | pthread_t *t;
|
|---|
| 24 |
|
|---|
| 25 | t = (pthread_t *)malloc(sizeof(pthread_t) * SIGMA);
|
|---|
| 26 | array = (int *)malloc(sizeof(int) * SIGMA);
|
|---|
| 27 |
|
|---|
| 28 | //__VERIFIER_assume(t);
|
|---|
| 29 | //__VERIFIER_assume(array);
|
|---|
| 30 |
|
|---|
| 31 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 32 | pthread_create(&t[tid], 0, thread, 0);
|
|---|
| 33 | array_index++;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 37 | pthread_join(t[tid], 0);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | for (tid=sum=0; tid<SIGMA; tid++) {
|
|---|
| 41 | sum += array[tid];
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | __VERIFIER_assert(sum == SIGMA); // <-- wrong, different threads might use the same array offset when writing
|
|---|
| 45 |
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.