Skip to content

Commit 687aca1

Browse files
authored
compute/synchronization: Add link to the lab 8 archives and fix typos
- Add links to the lab archive and change directory references. - Fix typo in `tls-on-demand` TODO. Signed-off-by: Vlad Hosu <[email protected]>
1 parent da43789 commit 687aca1

File tree

10 files changed

+17
-15
lines changed

10 files changed

+17
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The contents of the lab are located in the [lab archive](https://github.com/cs-pub-ro/operating-systems/raw/refs/heads/lab-archives/Lab_8_Synchronization.zip) and in the [GitHub repository](https://github.com/cs-pub-ro/operating-systems).

chapters/compute/synchronization/drills/tasks/apache2-simulator-condition/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ There are a few rules though, such as:
2222
- The consumer must not retrieve data if the buffer is empty.
2323
- The producer and the consumer can't access the shared buffer at the same time.
2424

25-
Now enter `chapters/compute/synchronization/drills/tasks/apache2-simulator-condition/` and run `make skels`.
26-
Look at the code in `chapters/compute/synchronization/drills/tasks/apache2-simulator/support/src/producer_consumer.py`.
25+
Now enter the `apache2-simulator-condition/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/apache2-simulator-condition/` if you are working directly in the repository) and run `make skels`.
26+
Look at the code in `support/src/producer_consumer.py`.
2727
We have one producer and one consumer for simplicity.
2828
Observe that the producer calls `notify()` once there is data available, and the consumer calls `notify()`, when data is read.
2929
Notice that this call is preceded by an `acquire()` call, and succeeded by a `release()` call.
@@ -58,7 +58,7 @@ Neat!
5858
So now we have both synchronization **and** signalling.
5959
This is what conditions are for, ultimately.
6060

61-
Open `chapters/compute/synchronization/drills/tasks/apache2-simulator/support/src/apache2_simulator_condition.py` and follow the TODOs.
61+
Open the `apache2-simulator-condition/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/apache2-simulator-condition/` if you are working directly in the repository), then go to `support/src/apache2_simulator_condition.py` and follow the TODOs.
6262
The code is similar to `apache2_simulator_semaphore.py`, but this time we use condition variables as shown in `producer_consumer.py`.
6363

6464
[Quiz](../../../drills/questions/notify-only-with-mutex.md)

chapters/compute/synchronization/drills/tasks/atomic-assembly/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ It is not an instruction with its own separate opcode, but a prefix that slightl
1111
For example, we cannot place it before a `mov` instruction, as the action of a `mov` is simply `read` or `write`.
1212
Instead, we can place it in front of an `inc` instruction if its operand is memory.
1313

14-
Go in `chapters/compute/synchronization/drills/tasks/atomic-assembly/` and run:
14+
Go in the `atomic-assembly/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/atomic-assembly/` if you are working directly in the repository) and run:
1515

1616
```bash
1717
make skels
1818
```
1919

20-
Look at the code in `chapters/compute/synchronization/drills/tasks/atomic-assembly/support/src/race_condition_lock.asm`.
21-
It's an Assembly equivalent of the code you've already seen many times so far (such as `chapters/compute/synchronization/drills/tasks/race-condition/support/c/race_condition.c`).
20+
Look at the code in `support/src/race_condition_lock.asm`.
21+
It's an Assembly equivalent of the code you've already seen many times so far (such as `race-condition/support/c/race_condition.c`).
2222
The 2 assembly functions (**increment_var** and **decrement_var**) are called by `race_condition_lock_checker.c`
2323

2424
Now add the `lock` prefix before `dec`.

chapters/compute/synchronization/drills/tasks/race-condition-atomic/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Modern processors are capable of _atomically_ accessing data, either for reads o
1313
An atomic action is an indivisible sequence of operations that a thread runs without interference from others.
1414
Concretely, before initiating an atomic transfer on one of its data buses, the CPU first makes sure all other transfers have ended, then **locks** the data bus by stalling all cores attempting to transfer data on it.
1515
This way, one thread obtains **exclusive** access to the data bus while accessing data.
16-
As a side note, the critical sections in `chapters/compute/synchronization/drills/tasks/race-condition/support/c/race_condition_mutex.c` are also atomic once they are wrapped between calls to `pthread_mutex_lock()` and `pthread_mutex_unlock()`.
16+
As a side note, the critical sections in `race-condition/support/c/race_condition_mutex.c` are also atomic once they are wrapped between calls to `pthread_mutex_lock()` and `pthread_mutex_unlock()`.
1717

1818
As with every hardware feature, the `x86` ISA exposes an instruction for atomic operations.
1919
In particular, this instruction is a **prefix**, called `lock`.
@@ -27,19 +27,19 @@ Compilers provide support for such hardware-level atomic operations.
2727
GCC exposes [built-ins](https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html) such as `__atomic_load()`, `__atomic_store()`, `__atomic_compare_exchange()` and many others.
2828
All of them rely on the mechanism described above.
2929

30-
Go to `chapters/compute/synchronization/drills/tasks/race-condition-atomic/` and run:
30+
Go to the `race-condition-atomic/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/race-condition-atomic/` if you are working directly in the repository) and run:
3131

3232
```bash
3333
make skels
3434
```
3535

36-
Now enter `chapters/compute/synchronization/drills/tasks/race-condition-atomic/support/src/race_condition_atomic.c` and complete the function `decrement_var()`.
36+
Now enter `support/src/race_condition_atomic.c` and complete the function `decrement_var()`.
3737
Compile and run the code.
3838
Its running time should be somewhere between `race_condition` and `race_condition_mutex`.
3939

4040
The C standard library also provides atomic data types.
4141
Access to these variables can be done only by one thread at a time.
42-
Go to `chapters/compute/synchronization/drills/tasks/race-condition-atomic/support/race_condition_atomic2.c`, compile and run the code.
42+
Go to `support/src/race_condition_atomic2.c`, compile and run the code.
4343

4444
After both tasks are done, go in the checker folder and run it using the following commands:
4545

chapters/compute/synchronization/drills/tasks/race-condition/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C: Race Conditions
22

3-
Go to `chapters/compute/synchronization/drills/tasks/race-condition/support/c/race_condition_mutex.c` and notice the differences between this code and the buggy one.
3+
Go to the `race-condition/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/race-condition/` if you are working directly in the repository), then open `support/c/race_condition_mutex.c` and notice the differences between this code and the buggy one.
44
We now use a `pthread_mutex_t` variable, which we `lock` at the beginning of a critical section, and we `unlock` at the end.
55
Generally speaking, `lock`-ing a mutex makes a thread enter a critical section, while calling `pthread_mutex_unlock()` makes the thread leave said critical section.
66
Therefore, as we said previously, the critical sections in our code are `var--` and `var++`.

chapters/compute/synchronization/drills/tasks/threadsafe-data-struct/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Synchronization - Thread-Safe Data Structure
22

33
Now it's time for a fully practical exercise.
4-
Go to `chapters/compute/synchronization/drills/tasks/threadsafe-data-struct/support/`.
4+
Go to the `threadsafe-data-struct/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/threadsafe-data-struct/` if you are working directly in the repository), then open the `support/` folder.
55
In the file `clist.c` you'll find a simple implementation of an array list.
66
Although correct, it is not (yet) thread-safe.
77

chapters/compute/synchronization/drills/tasks/tls-on-demand/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The perspective of C towards TLS is the following: everything is shared by defau
44
This makes multithreading easier and more lightweight to implement than in other languages, like D, because synchronization is left entirely up to the developer, at the cost of potential unsafety.
55

66
Of course, we can specify that some data belongs to the TLS, by preceding the declaration of a variable with `__thread` keyword.
7-
Enter `chapters/compute/synchronization/drills/tasks/tls-on-demand/` and run `make skels`.
7+
Enter the `tls-on-demand/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/tls-on-demand/` if you are working directly in the repository) and run `make skels`.
88
Now enter `support/src` and follow the TODOs.
99

1010
1. Create the declaration of `var` and add the `__thread` keyword to place the variable in the TLS of each thread.

chapters/compute/synchronization/drills/tasks/tls-on-demand/solution/src/race_condition_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void *decrement_var(void *arg)
3636
var--;
3737

3838
/**
39-
* Print the value of `var` after it's incremented. Also print
39+
* Print the value of `var` after it's decremented. Also print
4040
* the ID of the thread. Use `pthread_self()` to get it.
4141
*/
4242
/* TODO 1: */

chapters/compute/synchronization/drills/tasks/wrap-the-for/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Wrap the Whole `for` Statements in Critical Sections
22

3-
Navigate to the `chapters/compute/synchronization/drills/tasks/wrap-the-for/` directory, run `make skels` and open the `support/src` directory.
3+
Navigate to the `wrap-the-for/` directory of the extracted archive (or `chapters/compute/synchronization/drills/tasks/wrap-the-for/` if you are working directly in the repository), run `make skels`, and open the `support/src` directory.
44

55
Here you will find two source files:
66

config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ lab_structure:
111111
- title: Lab 8 - Synchronization
112112
filename: lab8.md
113113
content:
114+
- reading/lab8.md
114115
- tasks/race-condition.md
115116
- tasks/wrap-the-for.md
116117
- tasks/race-condition-atomic.md

0 commit comments

Comments
 (0)