Assignment 2
Assignment 2
(NUML)
Department: BS-SE 4th Semester
Operating System
Assignment # 02
Presented By:
Muhammad Hammad RCF30154
Presented To:
Ms. Tehreem Tajammal
1. Producer-Consumer Problem: Describe the Producer-Consumer
Problem. How can it be solved using semaphores or message passing?
Answer:
Challenges:
Answer:
The Readers-Writers Problem occurs when multiple processes need to read from or
write to a shared resource (e.g., a database).
Challenges:
Multiple readers can read simultaneously.
A writer must have exclusive access.
If not handled properly, starvation may occur (e.g., writers may wait
indefinitely).
Using Semaphores:
o Maintain a read count.
o Use a semaphore for mutual exclusion.
o Ensure writers get priority when needed.
Using Read-Write Locks:
o Readers get shared access unless a writer is waiting.
o Writers get exclusive access.
Fairness Policies:
o Writers may be given priority to prevent starvation.
o FIFO ordering ensures fair access.
Answer:
Challenges:
Deadlock: If each philosopher picks up one chopstick and waits for the other, all
remain stuck.
Starvation: If a philosopher is always the last to get chopsticks, they may starve.
Possible Solutions:
Answer:
A video editing software processes multiple tasks such as rendering, audio processing,
and real-time effects in parallel.
Role of Multi-Threading:
Answer:
Ride-sharing apps like Uber and Yango process real-time tasks, including tracking, fare
calculation, and payment processing.
Use of Multi-Threading: