A question I have to solve til tomorrow

  • Thread starter FrostScYthe
  • Start date
In summary, the conversation discusses the problem of multiple producers and consumers in the context of an airline industry. The proposed solution involves creating separate processes for the airline, intermediary, and agency, each with their own shared memory and semaphores to control access to the flights and available seats. The problem also requires the use of mutual exclusion semaphores to prevent indefinite blocking of agencies when a flight is full. The solution will be implemented in C.
  • #1
FrostScYthe
80
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
  • #2
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. :yuck:
 
  • #3


This algorithm uses semaphores to synchronize the producer and consumer processes. The intermediary acts as a buffer between the producers (airlines) and consumers (agencies). The shared memory is used to store the available seats for each flight.

To allow for airlines to offer more than one flight, the algorithm can be modified to use threads instead of processes. Each thread would represent a different airline, and within each thread, the producer and consumer processes can be implemented for each flight. This would allow for multiple flights to be offered by different airlines simultaneously.

In order to do this, the code can be modified to create multiple threads, each with its own intermediary and semaphores. The producer and consumer processes can then be implemented within each thread, allowing for multiple flights to be produced and consumed at the same time.

Additionally, the capacity of the shared memory can be increased to accommodate for more flights and their respective seats. The algorithm can also be modified to keep track of the number of flights each airline has offered and limit it to a certain number if needed.

In conclusion, using threads instead of processes and making necessary changes to the shared memory and semaphores, the algorithm can be modified to allow for multiple flights to be offered by different airlines simultaneously.
 

1. What is the importance of solving this question by tomorrow?

The urgency of solving this question by tomorrow may be due to a time-sensitive experiment, a deadline for a project, or the need to present the findings at a conference or meeting.

2. What research methods can I use to solve this question efficiently?

The research methods that can be used to efficiently solve this question may include experiments, surveys, observations, data analysis, and literature reviews.

3. How can I ensure the accuracy and reliability of my findings?

To ensure the accuracy and reliability of your findings, it is important to use a scientific approach, follow proper research protocols, use appropriate sample sizes, and validate your results through multiple experiments or data sources.

4. What are some potential obstacles or challenges I may face in solving this question by tomorrow?

Obstacles or challenges that may arise in solving this question by tomorrow could include limited time or resources, unexpected results, technical difficulties, or conflicting information.

5. How can I effectively communicate and present my findings to others tomorrow?

To effectively communicate and present your findings tomorrow, it is important to organize your data in a clear and concise manner, use visual aids or graphs to enhance understanding, and practice your presentation beforehand.

Similar threads

  • Biology and Chemistry Homework Help
Replies
2
Views
4K
Replies
2
Views
3K
  • Nuclear Engineering
Replies
2
Views
4K
  • General Discussion
Replies
4
Views
7K
  • General Discussion
Replies
1
Views
8K
Back
Top