Skip to content

Commit a88cd21

Browse files
committed
Add stall printout and noinline.
1 parent 0691436 commit a88cd21

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

synchs1/philosophy01.cc

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void wait_until_uncomfortable() {
1414
// stoic philosophers are always comfortable
1515
}
1616

17+
[[gnu::noinline]] // prevent compiler optimization
1718
void poop_into(int stall) {
1819
stalls[stall] += 1;
1920
}
@@ -35,4 +36,9 @@ int main() {
3536
}
3637

3738
sleep(5);
39+
40+
// NB: data races here
41+
for (int i = 0; i != K; ++i) {
42+
printf("stalls[%d] = %llu\n", i, stalls[i]);
43+
}
3844
}

synchs1/philosophy02.cc

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void wait_until_uncomfortable() {
1414
// stoic philosophers are always comfortable
1515
}
1616

17+
[[gnu::noinline]] // prevent compiler optimization
1718
void poop_into(int stall) {
1819
stalls[stall] += 1;
1920
}
@@ -36,4 +37,9 @@ int main() {
3637
}
3738

3839
sleep(5);
40+
41+
// NB: data races here
42+
for (int i = 0; i != K; ++i) {
43+
printf("stalls[%d] = %llu\n", i, stalls[i]);
44+
}
3945
}

0 commit comments

Comments
 (0)