Hi I have to turn in pseudocode for an algorithm that will work the multiple
producer-consumer problem in this way. I want to write the problem because
you might understand it in a better way. There is an airline producer where
each airline has one flight, and each flight can have a random number of
seats between 60 and 200. There's an intermediary in which the airline puts
the flights, and there are consumer agencies that will "consume" the seats
available in the flight. The problem states that the flight maybe put
available for all agencies to consume seats as long as it is not "empty on
seats", once it's out of seats it's taken out and a new airline can enter
and put its flight. I hope I defined it clearly. The solution to the problem
has to be THE BARE FUNCIONALITY so we don't have to worry about objects and
stuff it's more on how to use the semaphores to sinchronize this process.
Also what changes would need to be made in order for the algorithm to allow
for the airlines to offer more than one flight,... I was thinking hmm
threads?

#define MAX SEATS 200

Intermediary(int capacity)
CREATE SHARED MEMORY (MAX SEATS); 
create semaphore available = capacity;
create semaphore occupied = 0; 
create semaphore mutexcl = 1; 
}
Producer() 
{ 
int capacity = rand(60,200);
Intermediary(capacity);
int seat; 
while (TRUE) { 
produce seat(seat); 
wait( available); 
wait( mutexcl); 
enter seat(seat); 
signal( mutexcl); 
if(signal( occupied))
exit(); 
} 
} 
Consumer() 
{ 
int seat; 
while (TRUE) { 
wait( occupied); 
wait( mutexcl); 
remove seat( seat); 
signal( mutexcl); 
signal( available); 
consume seat(item); 
} 
}

 

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to