Operating System Fundamentals 46 As an example we will slightly reconsider our email program. Suppose that we have a single thread that is responsible for adding and removing email from the inbox. We have seen that by having only one thread we remove critical sections. Is it possible in this type of solution to still have a separate thread that checks for new messages Yes A solution is to configure a message queue between the checking thread and the inbox manager thread as follows The main message processor will accept messages either a receiving thread or from a user interface thread. The processing thread can only process one single message at a time and its pseudocode would look like this Forever) { Wait for message from queue If (message is delete) Call delete function Else if (message is new)
Call new message function } The message queues in many operating systems will allow for the listener to timeout if that is important for the program being developed. Most operating systems send data across their message queues in a first-in-first-out (FIFO)
arrangement, and some allow for queue jumping so that important messages can be inserted at the very front of the list. Most operating system message queues provide fora backlog of messages. If a sender
quickly sends ten messages, the receiver must request each of the messages to remove them from the queue. This leads to a significant problem in that if the receiver is notable to process
the messages fast enough, you can end up with some strange results. Most people have probably used a computer atone time that was not responding even though you were typing.
After a few seconds, the program suddenly responded and all of the characters typed appeared instantly. This is an example where the typed characters were put into a message queue but the receiver the program) was busy doing other tasks.
Share with your friends: