Skip to content

Commit 94c3632

Browse files
dabund24michael-schwarz
authored andcommitted
recursive mutex regression tests for creation locksets
1 parent 928b706 commit 94c3632

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// PARAM: --set ana.activated[+] threadJoins --set ana.activated[+] threadDescendants --set ana.activated[+] creationLockset
2+
#define _GNU_SOURCE
3+
#include <pthread.h>
4+
5+
int global = 0;
6+
#ifdef __APPLE__
7+
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
8+
#else
9+
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
10+
#endif
11+
pthread_t id1, id2;
12+
13+
void *t1(void *arg) {
14+
pthread_mutex_lock(&mutex);
15+
global++; // RACE (the unlock statement in main doesn't fully unlock the recursive mutex)
16+
pthread_mutex_unlock(&mutex);
17+
return NULL;
18+
}
19+
20+
void *t2(void *arg) {
21+
global++; // RACE (the unlock statement in main doesn't fully unlock the recursive mutex)
22+
return NULL;
23+
}
24+
25+
int main(void) {
26+
pthread_create(&id1, NULL, t1, NULL);
27+
pthread_mutex_lock(&mutex);
28+
pthread_mutex_lock(&mutex);
29+
pthread_create(&id2, NULL, t2, NULL);
30+
pthread_mutex_unlock(&mutex);
31+
pthread_join(id2, NULL);
32+
return 0;
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// PARAM: --set ana.activated[+] threadJoins --set ana.activated[+] threadDescendants --set ana.activated[+] creationLockset
2+
#define _GNU_SOURCE
3+
#include <pthread.h>
4+
5+
int global = 0;
6+
#ifdef __APPLE__
7+
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
8+
#else
9+
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
10+
#endif
11+
pthread_t id1, id2;
12+
13+
void *t1(void *arg) {
14+
pthread_mutex_lock(&mutex);
15+
global++; // RACE (the unlock statement in main doesn't fully unlock the recursive mutex)
16+
pthread_mutex_unlock(&mutex);
17+
return NULL;
18+
}
19+
20+
void *t2(void *arg) {
21+
global++; // RACE (the unlock statement in main doesn't fully unlock the recursive mutex)
22+
return NULL;
23+
}
24+
25+
int main(void) {
26+
pthread_create(&id1, NULL, t1, NULL);
27+
pthread_mutex_lock(&mutex);
28+
pthread_create(&id2, NULL, t2, NULL);
29+
pthread_mutex_lock(&mutex);
30+
pthread_mutex_unlock(&mutex);
31+
pthread_join(id2, NULL);
32+
pthread_mutex_unlock(&mutex);
33+
return 0;
34+
}

0 commit comments

Comments
 (0)