-
semaphores
this a machine problem given to us, and i dont have any deep experience in programming, would anyone could help me on this...help badly need..thanks :(
Synchronization Problem:
In a cake factory, there are D machines making dough, IS machines making strawberry icing, VS machines making vanilla icing, and CS machine making chocolate icing. These machines are able to make 1 unit of dough/icing at different speed. The dough produced and placed in the universal dough pool, and each icing made by each type of icing machine are placed on separate icing pools (all strawberry icing made by each strawberry icing machine places all machines are placed on a different pool).
The factory employs chefs with different experience. The chocolate chef requires 1 unit of dough and 2 units of chocolate icing; the strawberry chef requires 1 unit of dough, 1 unit of strawberry and vanilla icing; the wedding chef requires 3 units of dough and 1 unit of each icing.
The chef will first gather the ingredients required to bake the cake. Once the ingredients are gathered the chef then waits in line to use one of N ovens in the factory. When the cake is ready, the oven signals the chef to bring the cake out of the oven and decorate it.
System requirements:
The solution must allow as much concurrency as possible avoiding deadlocks and starvations. The system must allow the user to input the values of the variables D, IS, S, CS, N. The status of each chef must also be visible, whether they are waiting for an ingredient (system must specify which ingredient), waiting for an oven, or waiting for the cake inside the oven. The system must also be able to show the status of the dough and icing pools, and be able to show the contents of each oven (identify which chef’s cake is inside the oven).
-Try to solve the synchronization problem using semaphores and monitors.
-implement features mention in the system requirements
-
A semaphore is like a value that is set when a resource is being accessed. For instance, if a file is being accessed by a thread the thread might set being_accessed to true. Then another thread that wants access to the resource knows to wait until being_accessed is false, so that they don't access it at the same time.
-
Wow. that's quiet the project. Especially because you are being asked to make the factory as efficient as possible. Ok, anyways....
No one here is going to write the code for you. But we will surely help once you start writting it yourself. What you absolutely must do is to put down those specifications on paper.
Draw the factory. The chefs, the machines, the ovens, the different pools as rectangles clearly labeled. Connect them with lines showing their relationships. The vanilla ice machine connecting to the ice pool for instance and the chefs connecting to the machines and ovens... Draw the whole factory like this.
Once you are done you will have a much clearer picture of the problem, will be able to start coding the skeleton of your program and will have a general view of how the objects will communicate between each other.
-
http://en.wikipedia.org/wiki/Dining_...ophers_problem
Is this homework? Do you understand the problem at all? You gave us the question, but you haven't shown us your attempt yet.
-
well i've tried doing it but its clearly imposible for me, the proffesor request us to do a fine and course grain solution...
for the dough and icing a created a buffer pool having a 10 slots...
then the three chef as a order, the first one is the wedding chef, then the starberry and lastly is the chocolate chef
what i did was use a p(mutex) to siganal the the other chef then get the required ingredients, different other p(await) to the buffer pools for me to know if it is full or if they have the ingrdients.
then if the pool has the ingedient minus to the total number of the buffer slot.
then p(await) to other pools to get the required ingredients...
then in the oven part implanning to use v(mutex) first to siganl the oven...
i could write a pseudo code but i cant put down the logic in to the code...could anyone help me on this...
thanks
-
This is the code for the dough machine:
Code:
dought()
{
p(dough_pool_empty);
buf_dough[rear] = new_dough;
rear = rear % 1;
v(dough_pool_full);
}
for the icing its similar
then for the chocolate chef
p(dough_pool_full)
new_dough = buf dough[front];
front = front %1;
p(CS_pool_full)
new_CS = buf_cs[front];
front = front % 2; // since that the chef needs 2 units of chocolate icing, i place 2 here,
kindy check if it is correct to do so....thanks
p(mutex)
v(oven_use)
bake_in_oven();
p(oven_use_empty)
v(dough_pool_empty)
v(cs_pool_empty)
}
please help me...the deadline is near
thanks...
-
This is the same as
Think about it. I don't think that's what you want. (If it is maybe you should just assign zero directly.)
Code:
front = front % 2; // since that the chef needs 2 units of chocolate icing, i place 2 here,
kindy check if it is correct to do so....thanks
You should search for and read up on the modulo operator: http://www.cprogramming.com/tutorial/modulus.html