Skip to content

Commit 323cf59

Browse files
bernhardmgrubersponce
authored andcommitted
Improve README for race and atomic exercise
1 parent 5e07c6d commit 323cf59

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

code/atomic/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.

code/atomic/atomic.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
#include <iostream>
33
#include <thread>
44

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-
165
int main() {
176
int nError = 0;
187

code/atomic/solution/atomic.sol.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
#include <iostream>
33
#include <thread>
44

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-
165
int main() {
176
int nError = 0;
187

code/race/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
## Instructions
33

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

0 commit comments

Comments
 (0)