Write a program that synchronizes the threads

Assignment Help C/C++ Programming
Reference no: EM131295985

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: EM131295985

Questions Cloud

Was there filling of the fire compartment by smoke : Was there filling of the fire compartment by smoke? What was the smoke flow from the compartment regarding any opening? What was the smoke movement?
Propose a detailed plan that focuses on password policies : Propose a detailed plan that focuses on password policies and authentication methods to protect the project from becoming public during the research and development phase.
Security is of utmost importance for businesses : Security is of utmost importance for businesses. The implementation of security procedures for both wired and wireless devices and use of firewalls are two ways that businesses combat internal and external security threats.
Provide a summary of your learning style : Provide a summary of your learning style.List your preferred learning strategies.Compare your preferred learning strategies to the identified strategies for your preferred learning style.Discuss how the awareness of individual learning styles, prefe..
Write a program that synchronizes the threads : CS314 Operating Systems - 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.
Assignment incorporates the concepts from prior weeks : The following assignment incorporates the concepts from prior weeks (variables, if-else logic, loops, and arrays), along with this week's topic of file input/output process.
What is the value of the temperature difference : When t is very large, what is the value of the temperature difference? What is the temperature of the water at this time? What could you do to your experimental apparatus to decrease the value of k in another run? What quantity does k measure?
Bought a new hard drive for your computer : You just bought a new hard drive for your computer. You plan to use this as a secondary hard drive to store all your UMA files. Once installed, what needs to be done to the drive and what do these two tasks do?
Write a program to model deadlock detection : Design, implement, and gather results for a set of experiments - Write a program to model deadlock detection - Write a program to model deadlock detection and Write a program that simulates a paging system

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Differences of absorption and variable costing

Discuss the advantages and disadvantages of absorption and marginal costing and what factors organisations are required to consider when using each of these methods

  Program for search the telephone number

To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN.

  Technical skills on opengl programming

CG 200 Computer Graphics - "Under the Sea" using OpenGL - your imaginations and use OpenGL with C/C++ programming to produce a scene(s) that represents what you envision could possibly be seen under the sea. Please note that an image with just the ..

  Explain the two different uses of the keyword virtual

Explain the two different uses of The keyword virtual

  Windows application that function like a banking account

Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance.

  Interface that manages scores from surfing contest

Create a program with a menu driven interface that manages the scores from a surfing contest. At start up, your program should read the attached file, pick the score out of each line and append it to a list of scores.

  Which is a question you ask of your database

Adding sample records to the table using both datasheets and forms, running queries, and producing reports to test the application occurs in which step of planning a database?

  Determine the larger and smaller integers

Determine the larger and smaller integers. Write out every second integer, starting with the larger one and stopping at the lower one. (note: if one number is even and one is odd, the lower value will not show up in the output).

  Investments produced a total

Nico is saving money for his college education. He invests some money at 7%, and $1500 less than that amount at 6%. The investments produced a total of $235 interest in 1 yr. How much did he invest at each rate?

  Write a cgi script that will parse a program

Show that Merge Sort has an O(n lg n) running time by timing the code on the computer - Overview of the program for loop

  Calculate and return the average of one of numerical values

Write a method that uses the array to output to the console the list of entries in reverse order. Each entry is displayed on a new line.

  Explain about the hierarchical model

Explain about the Hierarchical Model, Network Model, Relational Model and Object-Oriented Model

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