model answer for assignment 2
play

Model Answer for Assignment 2 In a factory, there are 3 component - PDF document

CMPT-300 02-01 E2 Model Answer for Assignment 2 In a factory, there are 3 component makers. Each maker produces a unique kind of components independently. All these components are stored in a moving belt with size 10 forwarding to the


  1. CMPT-300 02-01 E2 Model Answer for Assignment 2 In a factory, there are 3 component makers. Each maker produces a unique kind of components independently. All these components are stored in a moving belt with size 10 forwarding to the assemblers. Every two components of different kinds can be assembled into one product. Thus, there are in total 3 distinct kinds of products. Two screw drivers are needed to assemble a product. All screw drivers have same function. There are also 3 assemblers with same priority who are responsible for assembling the products using components. In total, there are 3 screw drivers. An assembler can only work on one product at a time. When an assembler gets both the components and screw drivers, she can assemble a product within a limited time varied from 0.01 second to 1 second. Otherwise, she has to wait until all the necessities are met. She can grab the components or screw drivers first. The order does not matter. However, she can only get one piece (component or screw driver) at one time. If an assembler decides to make another product before she starts to make the current product, she can put the components and screw drivers back and re-get the new components and screw drivers. But she has to put the screw drivers back right after she finishes a product, since other assemblers may need these screw drivers. A product is put into an unlimited product queue. An assembler cannot start a new product before she put the current product into the queue. Some restrictions apply to the products as follows. • No same kind of products can be next to each other in the product queue. • The difference of the number of any two kinds of products in the queue must be less than 10, for example, we can have 10 of product A and 15 of product B, but it is not allowed if we have 10 of A and 21 of B because the difference is 11 which is larger than 10. The scenario is shown in the following figure.

  2. Question Please analyze the system. Identify all places where deadlock may happen. For each of such place, do the following. 1. Give an example to show a deadlock would happen. 2. Propose a mechanism to avoid the deadlock from happening. You should keep your answer concise and easy to understand. Some segments of pseudo code may help. Answer Suppose • the components are component 1,2 and 3 • the products are A,B and C. Deadlock may happen at following places. 1.Screwdrivers Description: each assembler may take one screwdriver and try to get the second one. Solution: only the assembler who already got one screwdriver can take the last one. 2.Product queue. Description: Suppose the last product of the product queue is A. The number of product A in the queue is n. And the number of product B and C is (n+10). Solution: The assembler will check before the making to avoid such situation. 3.Component maker making the component. Description:

  3. if the components in the moving belt all are component 1 or all are component 1 and 2. Solution: the component maker will check before he put the component into the moving belt. 4.Assembler putting back the component. Description: when an assembler want to put back the components but there is no space available. Solution: If the number of the components in the moving belt is greater than 8,let the component maker stop making.

Recommend


More recommend