Operating System: Question Set – 14

Operating System: Question Set – 14

What are some common synchronization primitives?

  • Mutexes
  • Semaphores
  • Monitors
  • Condition Variables
  • Spinlocks

What is a semaphore?

A semaphore is a synchronization tool used to control access to shared resources.

  • Binary Semaphore: Can take values 0 or 1 (similar to a mutex).
  • Counting Semaphore: Can take non-negative integer values.

What are the two operations on a semaphore?

  • wait() (or P operation): Decrements the semaphore value. If it becomes negative, the process is blocked.
  • signal() (or V operation): Increments the semaphore value and wakes up a blocked process, if any.

What is a mutex?

A mutex (mutual exclusion) is a locking mechanism that ensures only one thread or process accesses a critical section at a time.

What is a monitor?

Internal mutual exclusion is used by a monitor, a high-level synchronization mechanism, to guarantee that only one process can use its functions at once.

What is a deadlock?

When two or more processes are waiting for resources in a state known as deadlock, none of them can move forward.

What are the necessary conditions for a deadlock to occur?

  • Mutual Exclusion
  • Hold and Wait
  • No Preemption
  • Circular Wait

What is starvation, and how is it different from deadlock?

  • Starvation: A process waits indefinitely for a resource due to scheduling policies or priorities.
  • Deadlock: Multiple processes are waiting for each other, causing a complete standstill.

What is a race condition?

A race condition occurs when multiple processes access shared resources simultaneously, and the final output depends on the order of execution.

What are condition variables?

Processes can wait for specific conditions to be met thanks to condition variables. To manage access to common resources, they collaborate with a mutex.

What is Peterson’s algorithm?

Peterson’s algorithm is a software-based solution to the critical section problem for two processes. It uses two variables:

  • flag[ ]: Indicates a process wants to enter the critical section.
  • turn: Indicates whose turn it is to enter the critical section.

What is the Bakery algorithm?

Several procedures make use of the Bakery algorithm. In order to wait their time to access the vital part, processes take a “number” (similar to a bakery ticket) and determine which number is the smallest.

What is the Producer-Consumer Problem?

The Producer-Consumer Problem involves two types of processes:

  • Producer: Adds items to a buffer.
  • Consumer: Removes items from the buffer.
    Synchronization ensures the buffer does not overflow or underflow.

What is the Readers-Writers Problem?

  • Readers: Only read shared data (can do so simultaneously).
  • Writers: Modify shared data (require exclusive access).
  • The problem is ensuring readers and writers don’t conflict.

Leave a Reply

Your email address will not be published. Required fields are marked *