A question I have to solve til tomorrow

  • Thread starter Thread starter FrostScYthe
  • Start date Start date
AI Thread Summary
The discussion centers on creating pseudocode for a multiple producer-consumer problem involving airlines, intermediary systems, and consumer agencies. Each airline produces flights with a random number of seats, and agencies consume these seats, with the intermediary managing the availability. The solution requires using semaphores for synchronization, with three distinct processes: the airline, the intermediary, and the agency. The airline manages its own shared memory and semaphores, while the intermediary serves as a mapping table to prevent conflicts. The final implementation will be in C, and the pseudocode will be shared once completed.
FrostScYthe
Messages
80
Reaction score
0
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);
}
}
 
Technology news on Phys.org
well, they gave us til later, lol.. turns out most of us were doing it wrong. What was explained anyway was that, we would have to have 3 separate processes. one being the airline, the intermediary, and the agency.

The airline-flight would have its own shared memory and semaphores created in there to control access to the flight.

The intermediary would act as a mapping table to match airlines with agencies, so that the agencies could chose where they want a seat, possibly controlled by semaphores to prevent more than one airline from editing one spot.

The agency would be a simple consumer consuming seats, the semaphores would be opened here and they would be mutual exclusion semaphores asking whether a sit is available or not, just to not leave indefinitely blocked agencies when the flight would be full.

When I get the pseudo code, I'll post it here. I will have to implement it in C eventually.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top