28.01.2015 Views

PDF format

PDF format

PDF format

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Problem 6 (25 Points)<br />

Consider a system that has W workers and M managers that continuously enter and<br />

leave an office. Work can only be done in teams consisting of 1 manager and 2 workers<br />

in the office. The detailed requirements are:<br />

• Managers arrive to a FCFS queue, and workers arrive to their own FCFS queue.<br />

• When the manager at the front of the queue is ready, he/she picks the next two<br />

workers for his team and tells them to begin working. Then, the next manager<br />

can form his/her team in a similar manner.<br />

• Workers tell their manager when they are done working and leave immediately.<br />

• A manager does not leave until all team members have said they are leaving.<br />

• After work is completed, the team members leave for a random amount of time<br />

before re turning.<br />

a) Describe the synchronization for the manager process by writing the manager<br />

process in terms of the counting semaphore primitives Signal() and Wait() and<br />

the semaphore and variable declarations. Note: You do not need to give the<br />

worker process code; i.e., you can assume that the worker process is given.<br />

b) Describe the use of each semaphore and the general logic of the manager<br />

process. You can do that using comments in your code.<br />

HINT: (Note: You may use the following skeleton.)<br />

struct {<br />

int manager;<br />

int worker[2];<br />

int n=0;<br />

} newTeam;<br />

// shared<br />

// manager of new team<br />

// which workers are forming a new team<br />

// how many entries in worker[2]<br />

... semaphore definitions ...<br />

Page 3 of 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!