master-degree-notes/Concurrent Systems/notes/3.md

28 lines
No EOL
905 B
Markdown

### Hardware primitives
Atomic R/W registers provide quite a basic computational model.
We can strenghten the model by adding specialized HW primitives, that essentially perform in an atomic way the combination of some atomic instructions.
Usually, every operating system provides at least one specilized HW primitive.
##### Most common ones:
- **Test&set:** atomic read+write of a boolean register
- **Swap:** atomic read+write of a general register (generalization of the above)
- **Fetch&add:** atomic read+increase of an integer register
- **Compare&swap:** tests the value of a general register, returns a boolean (result of the comparison, true if it is the same).
#### Test&Set
```
Let X be a boolean register
X.test&set() :=
tmp <- X
X <- 1
return tmp
(the function is implemented in an atomic way by the hardware by suspending the interruptions!)
```
###### How do we use it?
```
lock()