Re: The revelation of St. f0dder the Divine
- From: Alex McDonald <ar.mcdonald@xxxxxxxxxxxxxxxxx>
- Date: Tue, 23 Aug 2005 00:50:57 GMT
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 .
- Follow-Ups:
- Re: The revelation of St. f0dder the Divine
- From: f0dder
- Re: The revelation of St. f0dder the Divine
- References:
- The revelation of St. f0dder the Divine
- From: hutch--
- Re: The revelation of St. f0dder the Divine
- From: f0dder
- Re: The revelation of St. f0dder the Divine
- From: f0dder
- Re: The revelation of St. f0dder the Divine
- From: hutch--
- Re: The revelation of St. f0dder the Divine
- From: Donkey
- Re: The revelation of St. f0dder the Divine
- From: Donkey
- Re: The revelation of St. f0dder the Divine
- From: f0dder
- Re: The revelation of St. f0dder the Divine
- From: Donkey
- Re: The revelation of St. f0dder the Divine
- From: hutch--
- Re: The revelation of St. f0dder the Divine
- From: Alex McDonald
- Re: The revelation of St. f0dder the Divine
- From: hutch--
- The revelation of St. f0dder the Divine
- Prev by Date: Re: model of Z
- Next by Date: Re: The Donkey Challenge
- Previous by thread: Re: The revelation of St. f0dder the Divine
- Next by thread: Re: The revelation of St. f0dder the Divine
- Index(es):
Relevant Pages
|
Loading