23. (15pts) There is a driver reading in messages, i.e. packets, from a Network
ID: 3895913 • Letter: 2
Question
23. (15pts) There is a driver reading in messages, i.e. packets, from a Network Interface Card (NIC). A pointer to each packet, is stored in a bounded queue of length N. The queue is a FIFO. At random times one or more packets are inserted by the driver into the queue. It is important that the driver not be interrupted when inserting p TCP/IP side of the queue a reader module periodically reads in and removes all the packet pointers currently in the queue. Using one or more semaphores, write a pseudocode solution to this problem. Assume that no packets get dropped or lost, and remember the driver should be allowed to enter all the packets it's write module contains without being interrupted by the reader module. ackets into the queue. On the frown? do wrte w)Explanation / Answer
Here the code you have written works only for basic problem. It doesnot take into account the preference for writer and also do not shows the current pointer in the queue. The writer doesn't get preference here. there is a need to use multiple semaphores here.
semaphores : mutex,wrt.
Reader:
do{
wait(wrt);
//perform read
signal(wrt);
}while(true);
WRITER:
do{
wait(mutex); // Here writer first checks if driver is reading the message or not.
wait(wrt); // If yes, then it stops the driver
signal(mutex); // performs writing operation
//perform writing here
wait(mutex); // stops writing operation
signal(wrt); //allows reader to read
signal(mutex); //leaves the critical section
}while(true);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.