|
PowerBASIC Forums
![]() Programming
![]() XP vs 95/98 - threads - slow, slow, slow ??? (Page 1)
|
This topic is 2 pages long: 1 2 |
next newest topic | next oldest topic |
| Author | Topic: XP vs 95/98 - threads - slow, slow, slow ??? |
|
Chris Boss Member |
I just came across something that I find very strange. I wrote a simple program on Windows 95 that has two threads, which On my Windows 95 system the program runs quite fast. This PC is I recently purchased a new computer which has Windows XP Amazingly, this program I wrote runs slower on my XP system than Why is this ? Why would a program run slower on a Pentium 2.5 ghz machine than I know XP has lots of services running, but I deactivated about ------------------ IP: Logged |
|
Kev Peel Member |
One thing I have noticed with XP is that it doesn't crash (the OS itself) - it just 'slows down' after a lot of program GPFs. Does a reboot solve the problem? Have you checked for memory corruption in the program and run it through the debugger also? ------------------ IP: Logged |
|
Chris Boss Member |
I ran another test using another program that simply draws an image and then using the ScrollWindow API function scrolls the image diagonally. The Win95 (Pentium 166 mhz) system scrolled at 72 frames per second. The XP (Pentium 2.5 ghz) system scrolled at 2580 frames per second. As expected, the XP system was 35 times faster. This would seem to imply that the problem with the first program Has anyone experienced problems with slow thread speed on XP ? To Kev, The program in the test above is very sound and it is not GPF'ing. ------------------ IP: Logged |
|
Chris Boss Member |
Here is the code to the EZGUI 3.0 application that is slower on XP than Win95: Maybe there is something in my thread code that XP doesn't like.
------------------ IP: Logged |
|
Patrice Terrier Member |
Chris I am using several threads in my multimedia applications and they run much faster However when I have to deal with a lot of graphics I avoid to create/delete multiple Perhaps you should check this when you use your double buffers. Something else, what does your EZ_DoEvents do?
[This message has been edited by Patrice Terrier (edited March 04, 2004).] IP: Logged |
|
Chris Boss Member |
Well, I found the solution to my problem !!! It turns out XP didn't like the use of the SLEEP command In one thread I used SLEEP 5 and the other SLEEP 1 . I removed the sleep commands and ran the program again on XP and it ------------------ IP: Logged |
|
Chris Boss Member |
Patrice, The EZGUI 3.0 Canvas control creates its memory DC's and Bitmaps ------------------ IP: Logged |
|
Michael Mattias Member |
Another problem might be.. although this seems hidden somewhere in the code which accesses the third-party library... You say, quote: If the third-party library is, in fact, SENDing the message versus POSTing the message, this application is forcing thread switches instead of letting Windows handle it. Not to mention, if all the code is doing is drawing pictures, there's no reason that has to happen "right now" and can't wait for the next 'normal' CPU time slice for the GUI thread. Without analyzing the source code of the third-party library as used within the context of the specific application, of course, this analysis may be totally moot. But at least moot is free. MCM IP: Logged |
|
Chris Boss Member |
Michael, You are correct ! EZGUI does force a context switch and this is on purpose. Posting to the main GUI thread requesting it to update an image EZGUI 3.0 sends a message from the secondary threads to the main When EZGUI 3.0 sends a message from a thread to the main GUI thread By using critical sections and sendmessage EZGUI over comes any In EZGUI apps, the threads are never used for any GUI functionality. I read extensively about using threads before adding thread features EZGUI 3.0's thread features are very sound. As you can see from my posts above, I found the source of the I am now getting a couple hundred frames per second on my XP system now, ------------------ IP: Logged |
|
Kev Peel Member |
quote: Chris I was not inferring your code is buggy, I meant other programs that have been run (such as experimental\test code) since system startup I think Michael has a valid point about 'forcing' GDI messages through. ------------------ IP: Logged |
|
Chris Boss Member |
I have experimented with posting messages from a secondary thread to the main GUI thread and I found it unreliable on slower systems. You can get a backlog of messages which build up and the system EZGUI 3.0 forces a context switch on purpose and it actually works Context switchs are not a bad thing. They just need to be controlled. A secondary thread should not attempt to modify any GUI elements The problem with accessing a window outside of the thread it EZGUI handles this by forcing a context switch to the main GUI Also problems can result when more than one thread accesses GDI The thread code in EZGUI 3.0 was extremely well thought out and I just didn't anticipate the problem with using the SLEEP command The fact that a slow Win95 system runs the code faster than a ------------------ [This message has been edited by Chris Boss (edited March 04, 2004).] IP: Logged |
|
Michael Mattias Member |
I was intrigued by this discussion and was looking for info on "overflowing the message queue." I found in PSDK that NT/XP has a limit of 10,000 messages.. but could not find any limits for Win 9x/ME, nor could I find any good suggestions for querying the current "queued message count" and/or cleaning out the queue by handling the message (I guess I could "switchtothread" to force that to happen, but now all threads of application must cooperate and that seems kind of clunky). Any ideas?
IP: Logged |
|
Dominic Mitchell Member |
You can clean out the message queue by using PeekMessage() with the PM_REMOVE flag. For example, let's say the user is moving an object across the screen with the keyboard. You will usually end up with a backlog of keyboard messages in the PostMessage queue when the user releases the key. This results in the object overshooting the intended destination. This is easily solved by doing the following
The first call to PeekMessage() can be replaced with GetQueueStatus() so in theory using GetQueueStatus() together with PeekMessage() can be used to empty the posted message queue of most messages. ------------------ IP: Logged |
|
Chris Boss Member |
Comment about message backlog: When I was developing EZGUI 3.0 I ran tests to find the best way I tried posting a message which would eventually generate WM_PAINT I then tried a method of using SendMessage to generate the GUI Posting messages from a thread can be very tricky since you have Now EZGUI 3.0 does have the ability to post messages from a thread Unless you can track the pending message count, posting messages EZGUI 3.0 supports both techniques, sending a message (which is When EZGUI 3.0 sends or posts a message from a thread it generates I believe EZGUI 3.0's methods of communicating between a thread Just to make sure the programmer writes the thread code correctly, Threads are great, but they can also be dangerous if not used I would be interested to find out why Windows XP is more
[This message has been edited by Chris Boss (edited March 06, 2004).] IP: Logged |
|
Dominic Mitchell Member |
Chris, There are some misconceptions in your post. Don't get me wrong, I use SendMessage to synchronize threads a lot. It's easy to implement and effective. However, your statement that PostMessage is dangerous defies conventional wisdom. Every author I have read on the subject strongly recommended the use of PostMessage over SendMessage to communicate between threads because in the case of SendMessage if the receiving thread hangs, the sender is toast. SendMessageTimeout is a better choice if you must use SendMessage (this piece of advice I rarely follow myself). The problem you were seeing could not have been the result of a backlog of WM_PAINT messages because there are no WM_PAINT messages in the queue per se. It would have been caused by a backlog of the messages you were posting to generate the WM_PAINT messages. When a portion of any window created by a thread becomes invalid, the QS_PAINT wake flag for the thread is turned on. GetMessage/PeekMessage will synthesize a WM_PAINT message for the proper window when this flag is on. The flag is turned off only when all windows created by a thread have been validated. ------------------ IP: Logged |
This topic is 2 pages long: 1 2 All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.