Re: The revelation of St. f0dder the Divine



hutch-- wrote:
Alex,

As a matter of fact, Sleep() uses int 2Eh buried in NTDLL.DLL.

with the parameter 027h, NtDelayExecution, for Windows NT/2000, but not under Windows XP/2003, where SYSENTER is used if available, nor under 95/98 where NTDLL.DLL doesn't exist iirc; I haven't run either for many years now. The effect is the same; a wait for a timer to expire.


The
problem with a conventional CreateProcess() followed somewhere down the
code sequence was deallocating the 2 handles. It crashed every time on
both win95b and win98se. I even tried setting a time delay before
dealocating the memory but it crashed immediately on deallocation. I
then tried using a global structure instead of a local and deallocated
at the end of the app but it still crashed when the handles were
deallocated.

I could never reproduce the problem on any Intel hardware.

If this was a general feature of the K6 with 95/98, I would have expected just about all your apps to collapse in the same graceless heap. CreateProcess, CloseHandle and freeing memory are central to the way the OS works.



================================ Your polling loop is a lazy, sloppy, error prone and a not very efficent method of checking for task completion, and is to be avoided like the plague in a pre-emptive multitasking operating system. ================================

Test the example I posted for Donkey in another topic, ZERO percent is
really hard to improve on and it sems to run under Windows (pre-emptive
multitasking operating system) with no problems at all.

It's error prone and blocks the message loop (if there is one). The overhead becomes apparent when there are other tasks you're contunually interrupting (to do no more that wait again) and when there are many apps with polling all doing it.



Now I am not sure of the direction of your comen, do you reject the design of a polling loop when all Windows GUI apps use a polling message loop ?

The message loop is a hangover from the cooperative multitasker used in Windows 3. It's ugly, but that's evolution and backward compatability for you.


The message loop is driven by the arrival of messages on a queue; the app does _not_ poll for them (and it never has, not even under Win3). It processes them until the queue is empty. When the queue is empty, it waits; it does not spin around uselessly burning cycles polling an empty queue.

Polling, let me repeat, is a dead duck technique on a pre-emptive OS. Period.


================================== It is to be avoided _at all costs_ in a thread that creates any windows, as the window will "lock up" for the duration of the Sleep. ==================================

If you pause a thread for a specified duration using the Sleep() API,
have you done anymore than pause a thread ?

For threads with windows, everything stops for those windows. If a system-wide message gets stuck in your message queue waiting for your task, the whole gui stops. Plus the two expensive context switches (one out, one in).



================================== Worse, it will lock up the entire system should it fail to process system-wide broadcast messages while sleeping. ==================================

Never seen the problem myself in any Windows version from win95oem to
the late win2k I use. Click a mouse on an app that is frozen with
Sleep() and when the sleep api is finished, the app get the next
message from the message que.

Yes, that's true, if very unfriendly. And, to make the point again, system wide broadcast messages stuck waiting for your task locks up the entire gui for that second you Sleep(1000). Your apps will stagger along as system messages will keep getting blocked. Message loops in different tasks need to be cooperative. Breaking the rules, however arcane or inconvenient, just makes an app look crap.


--
Regards
Alex McDonald
.



Relevant Pages

  • Re: processor time allocation
    ... When an app is doing IO it does NOT show up in the task manager as process ... simply stating that my process is not getting cpu time really doesn't give ... > perfectly fine using Sleep to obtain a near 20 Hz frequency. ... > Which is that my App is CPU starved and windows wont give my app more than ...
    (microsoft.public.vc.mfc)
  • Re: Windows power management Idling customization?!
    ... Can I write an App that can do activity without ... reseting the idle timer so that windows goes to sleep? ... like Indexing service i does indexing while windows is idle but does stop ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Sleep API function
    ... I just have a bad impression of Sleep. ... is the type of thing that is sometimes not in the documentation. ... > Just that Sleep in one app doesn't normally affect other apps ... Windows switches to another process. ...
    (microsoft.public.vb.winapi)
  • Re: Windows.. its like coming home!
    ... gradual transition, especially in going from OS 9 to OS X. ... They needed something that could compete with Windows, ... mean by the "2 of every app" comment before - Apple took whatever apps ... I've found that because the Dock shows applications rather than windows, ...
    (comp.sys.mac.advocacy)
  • Re: Windows.. its like coming home!
    ... gradual transition, especially in going from OS 9 to OS X. ... They needed something that could compete with Windows, ... mean by the "2 of every app" comment before - Apple took whatever apps ... I've found that because the Dock shows applications rather than windows, ...
    (comp.sys.mac.advocacy)

Loading