source: CIVL/examples/translation/pthread/stateful01_false.c@ 50f834b

1.23 2.0 main test-branch
Last change on this file since 50f834b was bf46837, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added comments.

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

  • Property mode set to 100755
File size: 889 bytes
Line 
1/**
2* This program is taken from the Pthread benchmarks of SV-COMP 2014.
3* https://svn.sosy-lab.org/software/sv-benchmarks/tags/svcomp14/
4*/
5
6#include <pthread.h>
7
8pthread_mutex_t ma, mb;
9int data1, data2;
10
11void * thread1(void * arg)
12{
13 pthread_mutex_lock(&ma);
14 data1++;
15 pthread_mutex_unlock(&ma);
16
17 pthread_mutex_lock(&ma);
18 data2++;
19 pthread_mutex_unlock(&ma);
20}
21
22
23void * thread2(void * arg)
24{
25 pthread_mutex_lock(&ma);
26 data1+=5;
27 pthread_mutex_unlock(&ma);
28
29 pthread_mutex_lock(&ma);
30 data2-=6;
31 pthread_mutex_unlock(&ma);
32}
33
34
35int main()
36{
37 pthread_t t1, t2;
38
39 pthread_mutex_init(&ma, 0);
40 pthread_mutex_init(&mb, 0);
41
42 data1 = 10;
43 data2 = 10;
44
45 pthread_create(&t1, 0, thread1, 0);
46 pthread_create(&t2, 0, thread2, 0);
47
48 pthread_join(t1, 0);
49 pthread_join(t2, 0);
50
51 if (data1==16 && data2==5)
52 {
53 ERROR: goto ERROR;
54 ;
55 }
56
57 return 0;
58}
59
60
Note: See TracBrowser for help on using the repository browser.