Skip to content

Commit e41a033

Browse files
committed
Add fixed branched thread creation example (closes #327)
1 parent b6106ae commit e41a033

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// PARAM: --enable ana.int.interval
2+
#include <pthread.h>
3+
#include <assert.h>
4+
5+
int g = 1;
6+
pthread_mutex_t A = PTHREAD_MUTEX_INITIALIZER;
7+
8+
void *t_fun(void *arg) {
9+
return NULL;
10+
}
11+
12+
int main(void) {
13+
int x, r;
14+
pthread_t id;
15+
16+
if (r) {
17+
pthread_create(&id, NULL, t_fun, NULL);
18+
19+
pthread_mutex_lock(&A);
20+
g = 5;
21+
pthread_mutex_unlock(&A);
22+
}
23+
else {
24+
g = 10;
25+
}
26+
27+
pthread_mutex_lock(&A);
28+
x = g; // may read 10!
29+
assert(g <= 5); // UNKNOWN!
30+
pthread_mutex_unlock(&A);
31+
return 0;
32+
}

0 commit comments

Comments
 (0)