Commit c95ef02

mo khan <mo@mokhan.ca>
2021-03-28 19:22:56
Answer more in assignment 2
1 parent a18f5c4
Changed files (1)
doc/assignment2.md
@@ -166,8 +166,36 @@ process gets to execute next. Processes sometimes need to access resources (chop
 need to be able to do this in a safe way without contention (sharing a chopstick).
 
 1. Define the two-phase locking protocol. (6 marks)
+
+  Locks are applied and removed in two phases:
+
+    * Expanding/Growing phase: locks are acquired and no locks are released.
+    * Shrinking phase: locks are released and no new locks are taken.
+
+
 1. Describe how an adaptive mutex functions. (6 marks)
+
+  > An `adaptive mutex` protects access to every critical data item.
+  > On a multiprocessor system, an adaptive mutex starts as a standard
+  > semaphore implemented as a spinlock. If the data are locked and therefore
+  > already in use, the adaptive mutex does on of two things. If the lock
+  > is held by a thread that is currently running on another CPU, the thread
+  > spins while waiting for the lock to become available, because the thread
+  > holding the lock is likely to finish soon. If the thread holding the lock
+  > is not currently in run state, the thread blocks, going to sleep until it
+  > is awakended by the release of the lock. It is put to sleep so that it will
+  > not spin while waiting, since the lock will not be freed very soon.
+
 1. Describe a scenario in which the use of a reader-writer lock is more appropriate than using another synchronization tool, such as a semaphore. (6 marks)
+
+    Reader-writer locks are most useful in the following situations:
+
+    * In applications where it is easy to identify which processes only read shared data and which processes only write shared data.
+    * In applications that have more readers than writers. This is because reader-writer locks generally require more overhead to establish than semaphores or mutual-exclusion locks.
+      The increased concurrency of allowing multiple readers compensates for the overhead involved in setting up the reader writer lock.
+
 1. What is the difference between deadlock prevention and deadlock avoidance? (6 marks)
+
 1. Describe a wait-for graph, and explain how it detects deadlock. (6 marks)
+
 1. Describe how a safe state ensures that deadlock will be avoided. (6 marks)