Lecture 7
Review
A comparison of synchronization primitives
| Primitive | Blocking | Signaling | Mutual Exclusion | Ownership |
|---|
| Mutex | yes | no | yes | yes |
| Spinlock | no | no | yes | yes |
| Conditional Variable | yes | yes | no | no |
| Semaphore | yes | yes | if only 1 | no |
Blocking: The transition of a process from the ready state to the waiting state. In other words, it is put to sleep.
If a process tries to acquire a mutex and is unable to, that process will be blocked.
The thread that acquires a mutex, or a spinlock, is the owner of that thread.
A spinlock keeps executing a process over and over again that doesn't do anything, while waiting for some condition to change in between each of the checks that it performs. Taking this design consideration into mind, you do not want to use a spinlock on a single-core architecture.
If the computer's processor has multiple cores, and if the critical period is of a very short duration, it may be less expensive to use a spinlock.
Deadlocks
We can avoid deadlocks by using Dijkstra's Banker algorithm, which ensures that we always maintain a safe state, while still allowing for greater concurrency.
Questions from last semester
Lecture 7 Question 4
- How can two processes share segments?
- What are some possible issues with segmented memory management, and how can they be fixed?
Lecture 7 Question 5
- The size of a page is always a power of 2. Give two reasons why.
- Consider a logical virtual address space of 8 pages, each 1024 bytes in size, where the logical address space is mapped onto a physical memory of 32 frames
- How many bits are there in the logical address?
- Answer: 13 bits.
2^3 for the page number, 2^10 for the location within the page. this question will appear on the midterm
- How many bits are there in the physical address?
There are 32-13 in the physical address. We need 10 to represent each part within a page. 5 bits to represent each of the 2^5 frames, 10 its to represent each of the 2^10 bytes within the page.
If the page size isn't a power of two, it is more expensive computationally to determine the logical and physical addresses. There would also be page numbers possible to set in the address, that don't actually exist.
For the logical address, we need 3 bits to represent which page among the 2^3 pages, and 10 bits to represent what byte within the 2^10 bytes on a page. For the physical address, we need 10 bits to reference every single byte within a 2^10 size page, and we need 5 bits for the 2^5 page frames
Questions from this semester
Question 1
When would you use fine-grained locking and when would
you use coarse grained locking?