Skip to content

Commit 627e9c8

Browse files
Add barrierception examples
1 parent ee8ea09 commit 627e9c8

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// NOMAC PARAM: --set ana.activated[+] 'pthreadBarriers'
2+
// In this example, the barriers "deadlock"
3+
#include<pthread.h>
4+
#include<stdio.h>
5+
#include<unistd.h>
6+
#include<goblint.h>
7+
8+
int g;
9+
int h;
10+
11+
pthread_barrier_t barrier;
12+
pthread_barrier_t barrier2;
13+
pthread_mutex_t mutex;
14+
15+
void* f1(void* ptr) {
16+
g = 2; //NORACE
17+
pthread_barrier_wait(&barrier);
18+
pthread_barrier_wait(&barrier2);
19+
20+
return NULL;
21+
}
22+
23+
int main(int argc, char const *argv[])
24+
{
25+
int top;
26+
int i = 0;
27+
28+
pthread_barrier_init(&barrier, NULL, 2);
29+
pthread_barrier_init(&barrier2, NULL, 2);
30+
31+
pthread_t t1;
32+
pthread_create(&t1,NULL,f1,NULL);
33+
34+
if(top) {
35+
pthread_barrier_wait(&barrier2);
36+
pthread_barrier_wait(&barrier);
37+
i = 2;
38+
}
39+
40+
__goblint_check(i == 0);
41+
42+
43+
44+
return 0;
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// NOMAC PARAM: --set ana.activated[+] 'pthreadBarriers'
2+
// This example exploits information on one barrier to become more precise for the other. Inception!
3+
#include<pthread.h>
4+
#include<stdio.h>
5+
#include<unistd.h>
6+
#include<goblint.h>
7+
8+
int g;
9+
int h;
10+
11+
pthread_barrier_t barrier1;
12+
pthread_barrier_t barrier2;
13+
pthread_mutex_t mutex;
14+
15+
void* f1(void* ptr) {
16+
pthread_barrier_wait(&barrier1);
17+
pthread_barrier_wait(&barrier2);
18+
19+
return NULL;
20+
}
21+
22+
int main(int argc, char const *argv[])
23+
{
24+
int top;
25+
int i = 0;
26+
27+
pthread_barrier_init(&barrier1, NULL, 2);
28+
pthread_barrier_init(&barrier2, NULL, 2);
29+
30+
pthread_t t1;
31+
pthread_create(&t1,NULL,f1,NULL);
32+
33+
if(top == 2) {
34+
pthread_barrier_wait(&barrier1);
35+
} else if (top == 3) {
36+
// Here, we cleverly exploit the additional MHP information, that for f1 to call wait on barrier2,
37+
// it must have seen a call to wait by main on barrier1.
38+
pthread_barrier_wait(&barrier2);
39+
i = 2;
40+
}
41+
42+
__goblint_check(i == 0);
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)