0% found this document useful (0 votes)
9 views7 pages

RK21GTA01 - Assignment - Simulation Based - CSE316 - CSE316 CA2

The document outlines a simulation-based assignment for an operating systems course, focusing on two problems involving synchronization and queue management using semaphores. The first problem describes a system where a teacher and students interact using semaphores to manage resources for assignments, while the second problem details a library queue system prioritizing teachers over students. The proposed solutions include specific semaphore management strategies to ensure efficient processing and minimize waiting times.

Uploaded by

loloo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

RK21GTA01 - Assignment - Simulation Based - CSE316 - CSE316 CA2

The document outlines a simulation-based assignment for an operating systems course, focusing on two problems involving synchronization and queue management using semaphores. The first problem describes a system where a teacher and students interact using semaphores to manage resources for assignments, while the second problem details a library queue system prioritizing teachers over students. The proposed solutions include specific semaphore management strategies to ensure efficient processing and minimize waiting times.

Uploaded by

loloo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSE316

OPERATING SYSTEM

CA3
SIMULATION-BASED
ASSIGNMENT

School of Computer Science & Engineering


LOVELY PROFESSIONAL UNIVERSITY
April 2023

SUBMITTED TO – Dr Baljit Singh Saini

Submitted By - DIVANSHI GUPTA


Registration Number - 12113417
Roll number - RK21GTA01
Section - K21GT
Solution Approach:
For the first problem, we can use semaphores to
synchronize the teacher and students. We can create
three semaphores, one for each item - pen, paper, and
question paper. The teacher will signal two semaphores
randomly, and the student having the third semaphore
will acquire the resources, complete the assignment,
and signal the teacher. This process will repeat until all
the assignments are completed.

For the second problem, we can use two separate


queues, one for students and one for teachers. Each
person will enqueue in their respective queue when they
enter the library. When a student is being serviced, and
a teacher arrives, we will give priority to the teacher by
serving them first. If multiple teachers arrive at the
same time, they will stand in their queue and get
serviced in a FIFO manner. To minimize the waiting
time of students, we will serve the teacher who arrived
while another teacher was being serviced next, followed
by students in the queue.

Logic:
Problem 1:

For synchronizing the teacher and the students, we can


use semaphores. We can use 4 semaphores - one for
each of the three items (pen, paper, question paper) and
one for the table. Initially, all the semaphores will be
initialized to 0.

The teacher process will run infinitely and it will keep


placing two random items on the table. Then it will
signal the semaphore for the table. After that, it will
wait for a student to complete the assignment by
waiting for the semaphore of the third item to be
signaled. Once the student signals the semaphore, the
teacher will remove the items from the table and the
cycle will continue.

The three student processes will run infinitely and they


will each wait for their respective item semaphore to be
signaled. Once the semaphore is signaled, the student
will pick up the item and check if there are two other
items on the table. If there are, it will signal the
semaphore of the third item and then start working on
the assignment. Once it completes the assignment, it
will signal the semaphore of the third item and go back
to waiting for its own item semaphore to be signaled

Problem 2:
We can use two semaphores - one for the students'
queue and one for the teachers' queue. Both of these
semaphores will be initialized to 1 initially. Whenever a
student or teacher enters the library, they will acquire
the corresponding semaphore and get added to the
queue. When the CPU is free, the process at the front of
the queue will be serviced.

If a student is being serviced and a teacher arrives, the


teacher will acquire the teacher semaphore and then
acquire the student semaphore before proceeding. This
will ensure that the student's request is completed
before the teacher's request.

If a teacher is being serviced and another teacher


arrives, the new teacher will acquire the teacher
semaphore and immediately proceed to the CPU. This
will ensure that the waiting time of the students is
minimized.
Code:
Problem 1:
Problem 2:

You might also like