Ask Question, Ask an Expert


Ask Operating System Expert

1. Synchronization within monitors uses condition variables and two special operation wait and signal. A more general form of synchronization will be to have a single primitive, waituntil, which had an arbitrary boolean predicate as the parameter. Therefore, one can say, such as waituntil x < 0 or y+z < n. The signal primitive will no longer be required. This scheme is clearly more general, but it is not used. Why not? Hint, think about the implementation.

2. Assume there are 2 threads T1, T2. Please describe if the following solution provides the correct synchronization for critical section which satisfies three conditions:  mutual exclusion, bounded wait and make progress.
T1                                                                          T2
Shared: int t1Inside = 0, t2Inside = 0;                       while (1) {
while (1) {                                                             while (t1Inside);
  while (t2Inside);                                                     t2Inside = 2;
  t1Inside = 1;                                                         // critical section
   // critical section                                                         t2Inside = 0;
   t1Inside = 0;                                                           }

3. Please prepare the pseudo code for the following problems:

1. Consider a pizza store which has 10 seats. A customer comes to buy pizza. If there is any unsold pizza left in the kitchen, he could get it immediately. If not, (s)he  needs to wait for chef to make one. After the customer gets the pizza, (s)he will grab a seat and start eating. If there is no seat, (s)he needs to wait. When (s)he finishes eating, (s)h would left the store. The chef in the kitchen just keeps making pizza. Though, (s)he stops if there are 5 unsold pizza left in the kitchen. If a customer come to buy one, (s)he resumes the work to make new pizza. Please prepare pseudo code for both customer and chef using semaphore to solve this problem, and synchronize chef and customers.

Programming Problem: 

4. prepare a multi-threaded program to solve producer and consumer problem.

• There are two types of worker thread: producer and consumer. A producer thread  randomly generate an integer between 0-100 (You could use random()/srandom()  or drand48()/srand48() to generate random number in C), and put it into the buffer. A consumer thread simple take the first integer from the buffer. A circular array must be used for the buffer. You don’t need loop for both types of thread. Each thread would exit after only consuming or producing one item (only once).

• Suppose total number of worker thread is 20, and buffer size is 10. Your program must randomly generate the number of producers and consumers. Their relationship must be : num_producers + num_consumers = num_threads, num_producer - num_consumer <= buffer_size, num_consumer <= num_producer, so that no thread will be blocked forever.  The order between consumer and producer threads must be arbitrary. Such as, you will not generate all producers(consumers) and then all consumers (producers). 

• Synchronize the producer and consumer.

• You could select any type of language (e.g. C/C++/Java) to execute this program. Your output will look like the following: 
Number of producer: 12 Number of consumer: 8
Thread 0 produce 63 in buffer 0, current number of items is 1
Thread 1 consume item 63 in buffer 0, current number of items is 0
Thread 3 produce 45 in buffer 1, current number of items is 1
Thread 5 produce 88 in buffer 2, current number of items is 2
Thread 4 consume item 45 in buffer 1, current number of items is 0
There are still 4 items left in the buffer: 96,26,52,81

• Please check blackboard for more reference about pthread library if you select to use it.

• Please submit all source code and a simple readme file on how to compile your code and the sample output. Please zip all files into a single zip file and submit through blackboard.

Operating System, Computer Science

  • Category:- Operating System
  • Reference No.:- M91317

Have any Question? 

Related Questions in Operating System

Lab-file processingobjectivesbulladd persistent data

Lab-File Processing OBJECTIVES • Add persistent data storage to your Week 4 Lab using text file input/output. PROBLEM: Stocks4U Portfolio Management System The portfolio management system you developed for Stocks4U needs ...

Securing operating systemsin this document of 2-3 pages

Securing Operating Systems In this document of 2-3 pages, respond to the following: • Describe the specific security concerns or risks that your chosen operating system is exposed to and how you plan to mitigate the risk ...

1 consider a system of 9 processes p p1 p10 associated

1. Consider a system of 9 processes, P = {p1, ..., p10} Associated with the system are 6 memory cells, M = {M1, .., M6}. The domain and range for each process is given in the following table: Process pi Domain D(pi) Rang ...

Assignment exploring the machinein this assignment you will

Assignment: Exploring the Machine In this assignment, you will explore a computer (i.e., a Windows PC or a Mac computer). Specifically, you will view the system's general information, create a folder on the desktop of th ...

Linux implementation proposalphelpstech llc has a new

Linux Implementation Proposal PhelpsTech, LLC. has a new research and development group - Medals. All systems in Medals will run the Linux operating system and will access resources, as well as share resources, with Phel ...

Web server practical-1 you are required to configure and

Web Server Practical- 1) You are required to configure and test a Web server to provide web hosting services to a client computer. Install and configure a web server, serving out a default web page that you have created. ...

Assignmentmultiple-processor scheduling simulationthe goal

Assignment Multiple-Processor Scheduling Simulation The goal of this simulation is to give you some experiences using POSIX Pthreads library functions for thread creations and synchronizations. You will learn how to solv ...

The following machine description will provide the basis

The following machine description will provide the basis for this assignment. You will create a virtual machine/operating system for the machine described below that will accept programs in the target machine language. T ...

Goals1 to gain hands-on experience with fork exec and wait

Goals: 1. To gain hands-on experience with fork(), exec(), and wait() system calls. 2. To master the basics of multi-process application development. 3. To appreciate the performance and fault-tolerance bene_ts of multi- ...

Firewall linux-a simple firewall is a filter which blocks

Firewall (Linux)- A simple firewall is a filter which blocks the packets based on the pre-defined filter rules. There are two general strategies to set-up a filter. One strategy is restrictive firewall which blocks all p ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate