A question I have to solve til tomorrow

  • Thread starter Thread starter FrostScYthe
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on solving the multiple producer-consumer problem in the context of airline seat allocation. The algorithm involves three processes: the airline, the intermediary, and the agency, utilizing semaphores for synchronization. The airline produces flights with a random number of seats between 60 and 200, while the intermediary manages the mapping between airlines and agencies. The consumer agencies utilize semaphores to ensure mutual exclusion when consuming available seats, preventing indefinite blocking when flights are full.

PREREQUISITES
  • Understanding of semaphores in concurrent programming
  • Familiarity with shared memory concepts
  • Basic knowledge of C programming language
  • Concept of producer-consumer problem in operating systems
NEXT STEPS
  • Research semaphore implementation in C using POSIX threads
  • Learn about shared memory management in C
  • Explore advanced producer-consumer algorithms
  • Study thread synchronization techniques in concurrent programming
USEFUL FOR

Software developers, particularly those working on concurrent systems, operating system students, and anyone interested in implementing producer-consumer algorithms in C.

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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
5K
Replies
2
Views
4K
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
9K