Pizza Studying Problem

The Pizza Studying Problem

 

Don't use plagiarized sources. Get Your Custom Essay on
Pizza Studying Problem
Just from $13/Page
Order Essay

Background

 

Develop a C program, named pizzastudy.c, that solves the following scenario using semaphores and (or) mutexes:

 

You and a group of classmates get together to study, but (of course) you can only study while eating Seasons pizza. All students in your group can only study when eating pizza (slices are not shared between students). Thus, the basic algorithm that a student follows is:

 

while(true){

pick up a slice of pizza

study while eating pizza slice

}

If someone (you or of your study partners) finds that there are no more slices of pizza L, they take a nap until another pizza arrives. However, the first person that finds that there is no more pizza will call up Seasons to order another pizza before taking a nap.

 

Your developed code should take in a single runtime argument representing the number of students in study group and should be between 2-5. You can assume there are 8 slices per pizza and your program should quit after 13 pizzas are consumed.

 

Your solution must synchronize between the student threads (determined by the number of students in the study group passed in as a runtime parameter) and the pizza delivery thread. You must ensure that deadlock situations are avoided, and that Seasons is only called one time for each ordered pizza.

 

Finally, your solution should print to the console information that includes when a student eats a slice of pizza (“Student 1 eats slice 5 from pizza 3”), when a new pizza is ordered (“Student 3 orders pizza 4”), and when a pizza is delivered (“Pizza 6 is delivered”).

1. Once working, include three screenshots of successful runs of the program along with the source code.

 

To ensure concurrent execution, use the sleep() function from unistd.h to mimic a studying or napping student. The following puts the current thread to sleep for 0-2 seconds.

 

#include <unistd.h>

// Going to sleep until the sleep function returns

sleep(rand() % 3);

// Guh! I’m awake!

The Homework Labs
Calculate your paper price
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

We ensure that all our papers are written from scratch. We deliver original plagiarism-free work. To guarantee this, we submit all work alongside a plagiarism report.

Free Revisions

All our papers are completed and submitted before the deadline. We ensure this to provide you with enough time to go through the work and point out any sections or topics that may need revision or polishing. We provide unlimited revision services for free.

Title-page

All papers have a title page providing your personal and institutional information. We do not charge you for this title page.

Bibliography

All papers have a bibliography or references page. This page is a requirement for academic and professional documents. We provide this page at no cost for all our papers.

Originality & Security

At Thehomeworklabs, we guarantee the confidentiality and security of your information. We value our clients and take confidentiality seriously. All personal information is treated with confidentiality and stored safely to ensure that no third parties gain access to it. We also provide original work and attach an originality/plagiarism report alongside all papers.

24/7 Customer Support

Our customer support team is available 24/7 to provide you with any necessary assistance when you need it. You can contact us at any time, day or night, via email or through the live chat button.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

We provide our customers with the best experience in the academic and business writing field.

Pricing

Flexible Pricing

We provide the best quality of service at affordable prices. We also allow our clients to make partial payments for their orders. You can also contact our customer support team in case you need to discuss a different payment plan.

Communication

Admission help & Client-Writer Contact

We realize that sometimes clarification is necessary to ensure that quality work is done. Therefore, we provide a button for clients and writers to communicate in case some clarification is needed.

Deadlines

Paper Submission

We ensure that we submit all papers ahead of their respective deadlines. This allows you to go through the documents and request any revision, corrections, or polishing before the paper is due.

Reviews

Customer Feedback

We encourage customer feedback, positive or negative. We can identify the various areas that we need to improve to provide even better services through your feedback. Please feel free to give us feedback.