What are practical applications of Queues?

Where message queues are used in the real time applications

  • Answer:

    A computer responding to user actions is a real time application that uses message queues. When the user hits a key, three messages are created and put into the message queue: 1 for key-down, 2 for key-released, 3 for key-pressed, each with associated information - a code for what action took place and information needed for that action. In the case of a key the information would vary depending on which key was hit. If the mouse is moved, the same thing happens, a message goes on the queue with appropriate information. Same with a mouse key click. These kind of actions generate interrupts and are acted on immediately. At the other end, the operating system is taking messages off the queue and delivering them to the proper place, i.e., for a key event, whichever window (application) has the focus, and whichever text component within the application, like a text box. For mouse events, the cursor is moved immediately and where it is on the screen will determine which window gets the message. The actual delivery of these event messages is a lot more complicated than that, but that is the general idea. There was a time in Windows programming when programmers had to know all this stuff. He/she had to write a special section of the program, I forget what it was called, but there you registered the program to receive these messages and then a long if (msg == KEYDN) [ ...code...} else if (msg == KEYUP) {...code...} and on, and on, handling each message as appropriate, and at the end telling the system whether you had handled the code or not by returning a code. This section of code was a loop that ran constantly while your application was running. You may still have to register a particular component to receive a particular kind of message, but it's much farther down the line and has been made much simpler and is today called an event rather than a message. The above loop was generally the first thing you wrote for any program, and one you usually had to go back to for changes again and again.

Anonymous at Answerbag.com Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.