source: CIVL/examples/translation/pthread/sigma_false.c@ d87ec9c

1.23 2.0 main test-branch
Last change on this file since d87ec9c was 289415b, checked in by John Edenhofner <johneden@…>, 12 years ago

Added more tests, modified the Pthread2CIVLTransformer

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

  • Property mode set to 100644
File size: 827 bytes
RevLine 
[09bc145]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;
[289415b]10int array_index = -1;
[09bc145]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
[16d81051]28 //__VERIFIER_assume(t);
29 //__VERIFIER_assume(array);
[09bc145]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.