View the step-by-step solution to:

# Due to a budget shortfall, it's become necessary for the computer science and electrical engineering departments to share conference rooms.

Due to a budget shortfall, it's become necessary for the computer science and electrical engineering

departments to share conference rooms. Faculty from these two departments don't like to mix and

the conference room is rather small, however, so the following rules apply:

there cannot be CS and EE faculty in the conference room simultaneously

there can never be more than 5 faculty members in the conference room simultaneously

Without synchronization, the body of each faculty thread would simply look like this:

while True:

useConferenceRoom()

You are to add synchronization code to implement the rules above. Your solution should avoid

both deadlock and starvation, and will consist of two separate thread bodies (one for each type of

faculty) . Below are some variables you can use in your solution (note that the lightswitch construct

is dened and its use illustrated on the last page of the exam):

empty = Semaphore(1)

turnstile = Semaphore(1)

CSswitch = Lightswitch()

CSmultiplex = Semaphore(5)

EEswitch = Lightswitch()

EEmultiplex = Semaphore(5)

Lightswitch Pattern

# Class definition

class Lightswitch:

def __init__(self):

self.counter = 0

self.mutex = Semaphore(1)

def lock(self, semaphore):

self.mutex.wait()

self.counter += 1

if self.counter == 1:

semaphore.wait()

self.mutex.signal()

def unlock(self, semaphore):

self.mutex.wait()

self.counter -= 1

if self.counter == 0:

semaphore.signal()

self.mutex.signal()

# e.g., Readers-Writers (no priority) solution:

## 0. Variables

roomLock = Semaphore(1)

## 1. Writers

roomLock.wait()

write()

roomLock.signal()

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents