- Doing things that make it seem like they’re going in parallel or even doing things in true
parallelism
Problem: Concurrency inside the OS
- Kernels have multiple processes and threads running parallely
- Kernels maintain different data structures (E.g., process tables) which can be accessed
at the same time. (-> Race Conditions)
Race Conditions
- Multiple threads/processes try to access shared data at the same time
- Result: data can be corrupted or changed
- Need to avoid at all costs
Critical Section
- Piece of code, share resources between threads/processes are changed
- Only one thread should be able to use this at a point in time (Problem)
Solution: Critical Section Problem
- Mutual exclusion (only one at a time)
- Progress: process should be able to enter the critical section at some point in time
- Fairness: wait times are distributed fairly, process cannot be made to wait forever
Mutual Exclusion
- Only one process at a time in the critical section
- Process need to get “permission” before entering the critical section
- Request a lock
- Hold a lock
- Release a lock
2 Shared Variables Used
- Turn: indicates which process is next to enter the
critical section
- Boolean Flag[2]: indicates that the process is ready
to enter the critical section
Side Note 1: Works well on older machines
Side Note 2: Can generalize to multi-process
Conclusion: Satisfies all critical section requirements
(Mutual Exclusion, Progress, Fairness)
Implementing Enforcing Mutual Exclusion: Hardware
- User code can’t access the hardware directly (requires system calls)
Disabling Interrupts - Disable the interrupts
- Carry out the critical section
- Re-enable interrupts
test_and_set() - Using an external function
- Set a boolean variable to true/false
swap_and_compare() - Same stuff as test_and_set() but uses
integer values and compares old/new
values
Implementing Enforcing Mutual Exclusion: OS Based
Solution Mutexes Semaphores
About Contains a boolean variable lock (to Contains an integer variable
indicate availability)
Functions to Manipulate Semaphores
Function to Manipulate a Mutex - wait(): resource acquired and
- Acquire(): call before CS var decremented
- Release(): call after CS - post(): resource released and
var incremented
Needs to be serialized
Needs to be atomic
When m is acquired, it needs to be
released
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller rahulravi1. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $20.61. You're not tied to anything after your purchase.