From e87d0dbde2f1534169b0ac61ae6f361b85c03b88 Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Sun, 30 Oct 2022 15:25:53 +1300 Subject: [PATCH] vault backup: 2022-10-30 15:25:53 --- content/notes/20-sync-deadlock.md | 31 +++++++++++++++++++++++++++++-- content/notes/cosc-204.md | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/content/notes/20-sync-deadlock.md b/content/notes/20-sync-deadlock.md index 6a559f517..151b6ade0 100644 --- a/content/notes/20-sync-deadlock.md +++ b/content/notes/20-sync-deadlock.md @@ -107,7 +107,34 @@ again: ``` -## for mutual exclusion -![slide|400](https://i.imgur.com/fkBl7PR.png) +semaphore without busy waiting ![](https://i.imgur.com/bLzY5q3.png) +![mutex|400](https://i.imgur.com/fkBl7PR.png) +![producer consumer again](https://i.imgur.com/ZN8bonW.png) +range of semaphore init vals +- 1 for mutex +- 0 for process sync +- >1 for concurrent processes/threads +- negative values tell us how many processes are waiting + +# Deadlock +Definition of deadlock: a set of processes is in a deadlocked state if every process is waiting for an event that can only be caused by another process in the set. + +![slide|400](https://i.imgur.com/XTSVwVI.png) + +conditions +- mutual exclusion: at least one of the held resources must be nonsharable +- hold and wait: must be at least one process holding a resource and one waiting +- no preemption: a resource can only be released by the process thats holding it +- circular wait: + - P1 is waiting on a resource held by P2; + - P2 is waiting on . . . + - Pn is waiting on a resource held by P1. + +typical solution +- break wait by acquiring lock in the same order +- ![](https://i.imgur.com/tDCTXWu.png) + +os solution +- ![](https://i.imgur.com/1qHM2w0.png) diff --git a/content/notes/cosc-204.md b/content/notes/cosc-204.md index f9ab8e5ad..b56e1a6fb 100644 --- a/content/notes/cosc-204.md +++ b/content/notes/cosc-204.md @@ -50,6 +50,7 @@ tags: - [17-processes-communication](notes/17-processes-communication.md) - [18-processes-sharing-and-threads](notes/18-processes-sharing-and-threads.md) - [19-cpu-scheduling](notes/19-cpu-scheduling.md) +- [20-sync-deadlock](notes/20-sync-deadlock.md) # Archive