source: CIVL/examples/pthread/esbmc/sigma_false.c@ 83af34d

1.23 2.0 main test-branch
Last change on this file since 83af34d was e3151da, checked in by Ziqing Luo <ziqing@…>, 11 years ago

re-organized example directory

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1763 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 827 bytes
Line 
1#include <stdlib.h>
2#include <pthread.h>
3#include <string.h>
4
5void __VERIFIER_assert(int expression) { if (!expression) { ERROR: goto ERROR; }; return; }
6
7const int SIGMA = 16;
8
9int *array;
10int array_index = -1;
11
12
13void *thread(void * arg)
14{
15 array[array_index] = 1;
16 return 0;
17}
18
19
20int 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.