source: CIVL/examples/pthread/esbmc/fib_bench_false.c@ bddaf4c

1.23 2.0 main test-branch
Last change on this file since bddaf4c 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: 580 bytes
Line 
1//Race condition: fixed with pthread_join's at bottom
2#include <pthread.h>
3
4int i=1, j=1;
5
6#define NUM 5
7
8void *
9t1(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
19void *
20t2(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
30int
31main(int argc, char **argv)
32{
33 pthread_t id1, id2;
34
35 pthread_create(&id1, NULL, t1, NULL);
36 pthread_create(&id2, NULL, t2, NULL);
37
38 pthread_join(id1, NULL);
39 pthread_join(id2, NULL);
40 if (i >= 144 || j >= 144) {
41 ERROR:
42 goto ERROR;
43 }
44
45 return 0;
46}
Note: See TracBrowser for help on using the repository browser.