File tree Expand file tree Collapse file tree 4 files changed +19
-25
lines changed Expand file tree Collapse file tree 4 files changed +19
-25
lines changed Original file line number Diff line number Diff line change
1
+
2
+ ## Instructions
3
+
4
+ You know this program already from "racing".
5
+ It tries to increment an integer 200 times in two threads.
6
+ Last time, we fixed the race condition using a lock, but now we'll try atomics.
7
+
8
+ Tasks:
9
+ - Replace the counter 'a' by an atomic.
10
+ Run the program, and check for race conditions.
11
+ - Go back to 'racing', and check the execution time of the atomic vs the lock solution,
12
+ e.g. using ` time ./atomic `
13
+ You might have to increase the number of tries if it completes too fast.
Original file line number Diff line number Diff line change 2
2
#include < iostream>
3
3
#include < thread>
4
4
5
- /*
6
- * You know this program already from "racing". It tries to increment an integer 200 times in two threads.
7
- * Last time, we fixed the race condition using a lock, but now we'll try atomics.
8
- *
9
- * Tasks:
10
- * - Replace the counter 'a' by an atomic. Run the program, and check for race conditions.
11
- * - Go back to 'racing', and check the execution time of the atomic vs the lock solution, e.g. using
12
- * time ./atomic
13
- * You might have to increase the number of tries if it completes too fast.
14
- */
15
-
16
5
int main () {
17
6
int nError = 0 ;
18
7
Original file line number Diff line number Diff line change 2
2
#include < iostream>
3
3
#include < thread>
4
4
5
- /*
6
- * You know this program already from "racing". It tries to increment an integer 200 times in two threads.
7
- * Last time, we fixed the race condition using a lock, but now we'll try atomics.
8
- *
9
- * Tasks:
10
- * - Replace the counter 'a' by an atomic. Run the program, and check for race conditions.
11
- * - Go back to 'racing', and check the execution time of the atomic vs the lock solution, e.g. using
12
- * time ./atomic
13
- * You might have to increase the number of tries if it completes too fast.
14
- */
15
-
16
5
int main () {
17
6
int nError = 0 ;
18
7
Original file line number Diff line number Diff line change 1
1
2
2
## Instructions
3
3
4
- * compile, run many times, see what happens
5
- * use a mutex to fix the issue
6
- * see the difference in execution time
4
+ * Compile, run many times, see what happens
5
+ * E.g. in bash, use: ` while true; do ./racing; done `
6
+ * (Optional) You can use ` valgrind --tool=helgrind ./racing ` to proof your assumption
7
+ * Use a mutex to fix the issue
8
+ * See the difference in execution time
9
+ * (Optional) Check agan with ` valgrind ` if the problem is fixed
You can’t perform that action at this time.
0 commit comments