Docsity

Solutions to Classical Synchronization Problems in Operating Systems, Assignments of Operating Systems

Partial preview of the text

Download Solutions to Classical Synchronization Problems in Operating Systems and more Assignments Operating Systems in PDF only on Docsity!

SUBJECT: CSC322 OPERATNING SYSTEMS

CONCEPTS

INSTRUCTOR: ZAHIDA WALAYAT

SUBMITTED BY: UMAIR AHMAD

REGISTRATION: FA18-BEE- 155

ASSIGNMENT# 2

COMSATS UNIVERSITY ISLAMABAD (CUI)

Solution

Classic Problems of Synchronization The following classic problems are used to test virtually every new proposed synchronization algorithm. 1 - The Bounded-Buffer Problem This problem is generalized in terms of the Producer Consumer problem, where a finite buffer pool is used to exchange messages between producer and consumer processes. Because the buffer pool has a maximum size, this problem is often called the Bounded buffer problem. Solution to this problem is, creating two counting semaphores "full" and "empty" to keep track of the current number of full and empty buffers respectively.

  1. do { /* produce an item in next produced / wait(empty); wait(mutex); / add next produced to the buffer */ signal(mutex) ; signal(full); } while (true);
  2. do { wait(full); wait(mutex); /* remove an item from buffer to next consumed / signal(mutex); signal(empty); / consume the item in next consumed */ } while (true);

Some potential solutions to the problem include:

  • Only allow four philosophers to dine at the same time. ( Limited simultaneous processes. )
  • Allow philosophers to pick up chopsticks only when both are available, in a critical section. ( All or nothing allocation of critical resources. )