Write a program that synchronizes the threads

Assignment Help Operating System
Reference no: EM131268314

Operating Systems Assignment Four: More IPC Problems

PROBLEM A:

Little rascals, Spanky, Alfalfa, and Darla are sitting around a table waiting to eat an ice cream sundae.  To eat a sundae, you need three things:jimmies, ice cream, chocolate sauce.

  • Spanky has ice cream and chocolate sauce.
  • Alfalfa has jimmies and chocolate sauce, and
  • Darla has jimmies and ice cream

Initially all three kids are "blocked."

Their lovely teacher, Miss Crabtree,   has an infinite supply of each item.  Miss Crabtree randomly places one item on the table, unblocking the kid who needs it, and then Miss Crabtree blocks (waits). The kid who needs that item takes it and eats. Only one item may be placed on a table at any time.  Each rascal waits for the one item he/she needs then consumes some ice cream for a random amount of time unblocking Miss Crabtree when he/she is done eating. Miss Crabtree then puts another item on the table and the scenario continues.

Write a program that synchronizes the threads such that deadlock does not occur and no little rascal starves. The output should specify which rascal is eating.

PROBLEM B:

Consider an orchestra conductor and a group of musicians. The musicians play independently but are coordinated by the conductor. For each measure of music indicated by the conductor's baton, the musicians play a set of notes. The musicians do not move onto the next measure until indicated by the conductor's baton. The Orchestra is called the Narcolepsy Symphony Orchestra because occasionally a musician falls asleep. When this happens the rest of the musicians continue playing. When the sleeping musician wakes up, the musician begins playing again with the orchestra.

Here are some guidelines:

  • Simulate 100 measures
  • Simulate 3 to 10 musicians
  • use one thread per musician. The thread doesn't die at the end of the measure... it lives for the duration of the piece.
  • use semaphores as the synchronization mechanism not pthread_join (since musician threads live across measures)
  • for each measure, there is a 25% chance that the musician will fall asleep
  • when a musician sleeps, it is for a random number of measures (say 1-5)... this is sleep amount is unknowable to the conductor.. the musician simply "wakes up" when it is ready to start playing again.
  • use the sleep method sleep() method to simulate sleep, sleeping players do a sleep(random 1-5) seconds to simulate sleeping.
  • do not to use sleep as a synchronization mechanism
  • in addition to outputting that it is playing, the musician thread should sleep(1) to simulate playing a measure...
  • provide feedback for each measure that looks something like this:

MEASURE 1:

Musician 3 playing

Musician 4 playing

Musician 1 playing

Musician 2 playing

MEASURE 2:

Musician 1 playing

Musician 3 playing

Musician 4 playing

MEASURE 3:

Musician 4 playing

Musician 1 playing

Musician 3 playing

MEASURE 4:

Musician 3 playing

Musician 2 playing

Note that: Musician 2 is sleeping in Measure 2 & 3 and Musicians 3 & 1 are sleeping in Measure 4

PROBLEM C:

Enhance the reader/writer problem we discussed in class using N readers and 1 writer so that the writer will not suffer from starvation.

Simulate readDB() and writeDB() using sleep().

Ensure that the delay for readDB() is much shorter than writeDB().

PROBLEM D:

Consider a doctor's office with a very overworked doctor.

The doctor has an examining room and a waiting room with a number of chairs in it. When the doctor finishes with a patient, the patient leaves and the doctor goes to the waiting room to see if there are other patients waiting. If there are, she brings one of them back to the examining room and examines the patient. If there are no patients waiting, she returns to her examining room, lies down on the examining table and goes to sleep.

Each patient (or I should say impatient), when he arrives, knocks on the examining room door to see what the doctor is doing. If the doctor is sleeping, then the patient wakes her up and enters the examining room. If the doctor is performing an examination, then the patient goes to the waiting room. If there is a free chair in the waiting room, the patient sits in it and waits his turn. If there is no free chair, then the patient leaves.

Assume there are 10 chairs in the waiting room. The doctor must be a thread. Each patient must be a thread, assume 13 patients, each running in an infinite loop to simulate arriving at the office, being examined (or not), then leaving... then repeat.

Reference no: EM131268314

Questions Cloud

State the domain of the given function : The perimeter of a rectangle is 100 m. Express the area A(l) as a function of the length l, and state the domain of this function.
Problem regarding the community intervention : What is the difference between "community intervention" and "intervention in the community"?
What is the budgeted total manufacturing overhead for year : What is the budgeted total manufacturing overhead for the year? What is the budgeted total selling and administrative expenses for the quarter? What was total cash received in March?
Competitive forces confronting sirius xm : How strong/medium/weak are the five competitive forces confronting Sirius XM? Perform the five forces analysis to support your answers.
Write a program that synchronizes the threads : CS314 Operating Systems Assignment Four: More IPC Problems. Write a program that synchronizes the threads such that deadlock does not occur and no little rascal starves. The output should specify which rascal is eating
Find the assignment plan that minimizes the company''s cost : Suppose that a company has four jobs to be assigned to four workers. The costs, in dollars, of assigning these jobs to these workers are given in Table 5.5.21. Determine the assignment plan that minimizes the company's total cost.
What experiences from electric train technology can utilize : What experiences from electric train technology can be utilized in the R&D of electric vehicle technology - Will electric vehicles be readily accepted by the public?
Efficient and effective communication : Communicating a Vision for Change. Assess John Kotter's views on efficient and effective communication. What means of communication are available to managers to share their vision for change?
How much should be invested : If part is invested at 5% and the rest at 9%, how much should be invested at 5% to yield 8% on the total amount?

Reviews

Write a Review

 

Operating System Questions & Answers

  Role of a database management system

Discuss the role of a database management system (DBMS) and what are its benefits and how does a relational database management system differ from a flat document?

  Explain how are two types of operating systems similar

What are the differences between a Windows operating system and a Linux operating system? What inherent security controls are included with each operating system? How are the two types of operating systems similar?

  Single machine with total capacity

Suppose that there is a single machine with total capacity of 23 units of time, and that one gets partial credit for partially processing a task, so that processing a task of value Vi for time t

  Many commands to complete basic functions

Unix is a command line interface it uses many commands to complete basic functions. When I think about the command line interface it takes me back to MS-DOS. Discuss 2-3 similarities or differences you see in the two interfaces

  A queue is a first-in, first-out list

A queue is a first-in, first-out list. The queue has two essential operations: enqueue, which appends an entry to the end of the list (called the tail ) and dequeue, which returns and removes the first entry in the list

  Deadlock to occur in multiprogramming environment

List the reasons which causes deadlock to occur in multiprogramming environment and discuss how can the deadlock detection algorithm for one resource find out if a deadlock exists in the above sequence

  The master distribution center in bend

The master distribution center in Bend, Oregon, has 42 people, including nine Windows 2000 users, 22 people using Windows XP Professional, and 11 people using Windows Vista Business Edition.

  Add two more files to mortgage calculator program

Add two more files to Mortgage calculator program. Mortgage calendar Class and Mortgage array Class.

  Formulate the linear programming model for this problem

Formulate the linear programming model for this problem Plot a graph indicating and labelling clearly all the constraints, the feasible region (R) and the optimal point (X)

  What is the equivalent of the root directory

Write the command you used. Can you think of an alternative to that command - Use the vi editor to create a file named lecture05.txt and type descriptions of the commands we are discussing - pwd, mkdir, rmdir, rm, cd, cp, and mv.

  What is file system reliability

What is file system reliability and explain the roles of error handling, back up, and file checker methods in supporting the file system reliability?

  G a proces switch, the operating system executes instruction

During a process switch, the operating system executes instructions that choose the next process to execute. These instructions are typically at a fixed location in memory. Why?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd