Re: Hutch, give it up.




hutch-- wrote:
> Waffle waffle everywhere and all the world did shrink,
> Waffle waffle everywhere and f0dder's bullsh*t stinks.
>
> ...and it does this by using the wait-state primitives of the OS,
> just like WaitForSingleObject, NOT by spinning in a polling loop.
>
> Like it or lump it, a GetMessage loop is a polling loop. Consultations
> with the "colonel" won't help you here as there has never been a
> garrantee that the internals of Windows will remain the same but we do
> know from testing that when the load drops, the system idle process
> increases.
>

I've tried to be careful in my use of words here, particularly

.. run and ready lists, which are OS maintained structures used for
scheduling tasks
.. msg queue, which is the list of queued messages through the WindProc
message loop.

They're all queues, but calling them all queues would have made this
description a little ambiguous.

The system idle process is exactly what its name suggests; a thread
that is run by the system when there is nothing to run in the ready
list. Its main function is to make sure the processor is interruptible,
then to halt the processor. It will be re-awoken when an external
interrupt occurs. Once an interrupt is received, the processor runs an
interrupt handler. It in turn invokes the scheduler to take the task
that was waiting for this interrupt, move it to the run list, and start
its execution.

To handle devices that do not interrupt, but require polling, the
system employs a hardware timer to periodically interrupt the
processor. This turns interrupt driven polling (the timer pops, but the
device may not be ready, so wait some more and try again later) into
what look like true interrupts for the device.

Beyond that type of pseudo-polling, no polling of any sort is carried
out by the OS. One of many excellent descriptions of how an OS pulls
off this interrupt driven trick is Andy Tanenbaum's /Operating Systems:
Design And Implementation/, which includes the source code for MINIX.
The original MINIX design contained a spin loop in the idle task.
Subsequent patches to the MINIX kernel removed this and replaced it
with a HLT instruction. Even an OS as small and as simple as MINIX can
do without polling.

Back to the message loop. When GetMessage finds there are no more
messages in the msg queue, it does not return to the calling task. As I
am not sure of the internals of Windows at this point (I certainly
haven't seen the code), I don't know how it accomplishes queue
management. However, based on what appears to happen, it appears to
employ the standard practice of a semaphore in a queue header. When the
task finds the queue is empty, issue a wait on it. Other tasks that add
to the queue then inspect the queue header; if it's in a waiting state,
then signal that there's something now on the queue. Both the wait and
the signal involve asking the OS to do something.

However the msg queue is signalled, the net effect is to involve the
OS. It moves this task from the run list to a wait list (which is what
is meant by blocking), and it won't schedule this task again until
another message is added to the msg queue by some other task.

Since our task is now waiting, the OS will look to run someone else
that is in the ready list. If there are no tasks in the ready list, the
OS schedules the System Idle task, where, as described above, no
polling at all takes place.

Net effect; the Windows message loop does not poll.

--
Regards
Alex McDonald

.



Relevant Pages

  • Re: Record Routing using MoveFirst and MoveNext
    ... This takes it to queue 6 ... goes into an infinite loop. ... >>> fashion to 3 different lists in access. ... >>> Dim rs As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • Re: MIDI conjunction device
    ... InputSelected is not NONE and stat1 is put into a queue. ... which will send out the queued bytes each time the TxEmpty interrupt ... and the OUT channel a queue of arbitrary length. ... messages to be sent without their status characters (ie, ...
    (comp.arch.embedded)
  • Re: Performance Intel Pro 1000 MT (PWLA8490MT)
    ... driver changed to not use the braindamaged sk interrupt moderation. ... with small 50-60 byte UDP packets. ... when the tx queue fills up, the application should stop sending, at ... For transmission, with non-broken hardware and software, ...
    (freebsd-performance)
  • Re: Some advice for a lisp newb
    ... an end node in a network of nodes is found by performing a breadth-first ... A bfs needs to know the end node for which it is searching, a queue ... list of lists. ...
    (comp.lang.lisp)
  • Q: wait queue weirdness in A/D device driver - 2.4.18 or 20, RH 8.0
    ... "master buffer" at interrupt time and wake up any ... it should be because the int handler has now placed data into the master ... I'm using gcc 2.95.3 for both kernel and module (due to a suggestion on ... into the queue. ...
    (comp.os.linux.development.system)