Skip to content

Commit 149e546

Browse files
committed
rf
1 parent e5e9965 commit 149e546

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.preservesafetywhenusingconditionvariables.PreserveSafetyWhenUsingConditionVariables
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <threads.h>
2+
3+
cnd_t condition;
4+
void t1(void *a) {
5+
cnd_signal(&condition); // NON_COMPLIANT
6+
}
7+
8+
void t2(void *a) {
9+
cnd_broadcast(&condition); // COMPLIANT
10+
}
11+
12+
void t3(void *a) {
13+
cnd_signal(&condition); // COMPLIANT (not a thread)
14+
}
15+
16+
void f1() {
17+
thrd_t threads[5];
18+
19+
mtx_t mxl;
20+
21+
mtx_init(&mxl, mtx_plain); // COMPLIANT
22+
23+
for (size_t i = 0; i < 1; i++) {
24+
thrd_create(&threads[i], t1, &mxl);
25+
}
26+
27+
for (size_t i = 0; i < 1; i++) {
28+
thrd_join(threads[i], 0);
29+
}
30+
31+
mtx_destroy(&mxl);
32+
return 0;
33+
}
34+
35+
void f2() {
36+
thrd_t threads[5];
37+
38+
mtx_t mxl;
39+
40+
mtx_init(&mxl, mtx_plain); // COMPLIANT
41+
42+
for (size_t i = 0; i < 1; i++) {
43+
thrd_create(&threads[i], t2, &mxl);
44+
}
45+
46+
for (size_t i = 0; i < 1; i++) {
47+
thrd_join(threads[i], 0);
48+
}
49+
50+
mtx_destroy(&mxl);
51+
return 0;
52+
}

0 commit comments

Comments
 (0)