Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Operating System

Assignment: 3
ClO3-SO3
1. Implementing a Mutex Lock:
Write a program in a language of your choice to implement a mutex lock
using atomic operations or low-level synchronization primitives provided by
the language (such as compare-and-swap or test-and-set instructions).
Demonstrate its usage in a multi-threaded program where multiple threads
access a shared resource.
2. Semaphore Implementation: Design and implement a counting semaphore
in pseudocode or a programming language. Include operations for
initializing the semaphore, acquiring (down) and releasing (up) the
semaphore, and handling blocking and waking up of threads. Test your
implementation with multiple threads accessing a shared resource.
3. Peterson's Solution Implementation: Implement Peterson's solution for
mutual exclusion in a two-process system. Use a programming language
that supports shared memory or inter-process communication.
Demonstrate how the two processes access a critical section without
interference and without deadlock.
4. Producer-Consumer Problem with Mutex: Solve the classic producer-
consumer problem using mutex locks. Design a program where multiple
producer threads generate items and place them in a shared buffer, and
multiple consumer threads retrieve items from the buffer. Ensure mutual
exclusion using mutex locks to prevent race conditions.
5. Reader-Writer Problem with Semaphores: Implement the reader-writer
problem using semaphores. Design a program where multiple reader
threads can read from a shared resource concurrently, but writers must
have exclusive access to write. Ensure fairness between readers and
writers.

You might also like