diff --git a/Concurrent Systems/notes/3.md b/Concurrent Systems/notes/3.md index e80771b..34e568d 100644 --- a/Concurrent Systems/notes/3.md +++ b/Concurrent Systems/notes/3.md @@ -6,3 +6,23 @@ We can strenghten the model by adding specialized HW primitives, that essentiall 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() \ No newline at end of file