Skip to content

Commit 997ff24

Browse files
Add further non-racy example
1 parent aa68509 commit 997ff24

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// NOMAC PARAM: --set ana.activated[+] 'pthreadBarriers'
2+
#include<pthread.h>
3+
#include<stdio.h>
4+
#include<unistd.h>
5+
6+
int g;
7+
8+
pthread_barrier_t barrier;
9+
pthread_mutex_t mutex;
10+
11+
void* thread_func(void* arg) {
12+
// Some initialization code
13+
pthread_barrier_wait(&barrier);
14+
15+
pthread_mutex_lock(&mutex);
16+
g = 5; //NORACE
17+
pthread_mutex_unlock(&mutex);
18+
19+
return NULL;
20+
}
21+
22+
23+
24+
int main(int argc, char const *argv[])
25+
{
26+
pthread_t worker1, worker2;
27+
28+
pthread_barrier_init(&barrier, NULL, 3);
29+
30+
pthread_create(&worker1, NULL, thread_func, NULL);
31+
pthread_create(&worker2, NULL, thread_func, NULL);
32+
33+
g = 8; //NORACE
34+
35+
pthread_barrier_wait(&barrier);
36+
return 0;
37+
}

0 commit comments

Comments
 (0)