Operating System Fundamentals



Download 2.34 Mb.
View original pdf
Page32/66
Date06.03.2023
Size2.34 Mb.
#60834
1   ...   28   29   30   31   32   33   34   35   ...   66
OperatingSystemFundamentals
best answers from c, Lesson 2 C# Windows Forms
Message Queues
A popular mechanism provided by many operating systems for the purpose of inter process communication is the concept of a message queue. In many multi-threaded programs there is often a lot of information that one thread will want to exchange with another thread rather than just doing synchronization. In order to send actual data from one thread to another, most operating systems provide a mechanism known as a message queue or a pipe. Ina message queue there is always at least one sender and one receiver. The sender creates a message and puts it into a queue for delivery by the operating system. The receiver listens to the queue for messages and will often block waiting for messages to arrive. Once the message arrives, the receiver is woken up and the message is processed.

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.

Download 2.34 Mb.

Share with your friends:
1   ...   28   29   30   31   32   33   34   35   ...   66




The database is protected by copyright ©ininet.org 2024
send message

    Main page