PowerBASIC Forums
  Programming
  XP vs 95/98 - threads - slow, slow, slow ??? (Page 2)

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone!
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
posted March 06, 2004 08:07 PM     Click Here to See the Profile for Chris Boss     Edit/Delete Message   Reply w/Quote
Dominic,

The problem with PostMessage was this:

The tests I ran were where the thread would calculate coordinates
, pass a message back to the main GUI thread to draw what the
thread designed, and then the thread would continue on an
calculate again. I was creating an animation where the thread
was running constantly and requesting the main thread to draw
what it designed.

When I posted the messages this is what happened:

The main GUI thread would get a message which requested an image
be drawn. It would draw the image on a memory DC and then invalidate
the client area so WM_PAINT would be generated. When WM_PAINT occured
the memory DC is BitBlt'ed to the client area.

Windows waits until no messages are pending before WM_PAINT
is generated.

What happened when I posted messages, the GUI thread would draw
the image, but the thread ended up posting the redraw messages
too fast and then main thread could not keep up. A backlog of
messages occured for some reason. Basically the program became
unstable. Whether the backlog was the WM_PAINT or just the
posted message itself wasn't apparent, but either way a backlog
occured.

When I switched to using SendMessage which forced a context switch
the problem disappeared and the main GUI thread kept up with the
worker thread (or maybe it was the worker thread was forced not
to go too fast because it had to wait on the return of sendmessage
from the main thread).

Because posting a message doesn't require the message to be
processed before the thread moves on, this is the inherent
danger of posting IMO.

The use of SendMessage forces a context switch so you have more
control.

The EZGUI program noted above, displays two different animations
using two threads simultaneously at high speed. This was the test
I used when adding thread support to EZGUI 3.0.

My comments are based on an actual real life test and the need
to find a solution.

EZGUI 3.0 does support posting a message from a thread, but it
also has a tracking system so the thread knows how many pending
messages exist. Without this tracking system, posting messages
would not be reliable IMO. There must be a system to prevent
a backlog of posted messages and that is what I implimented.

I am not concerned about any "recommended" method in books, but
only in what works.

I did do a good bit of research into using threads before deciding
the best solution.

------------------
Chris Boss
Computer Workshop
Developer of "EZGUI"
http://ezgui.com

IP: Logged

Dominic Mitchell
Member
posted March 06, 2004 11:15 PM     Click Here to See the Profile for Dominic Mitchell     Edit/Delete Message   Reply w/Quote
Posting a series of messages to a queue will cause a backlog. Keyboard and
mouse messages are good examples. Your problem was thread synchronization.
By switching from PostMessage to SendMessage you synchronize the threads.
The sending thread (worker) is put to sleep (it does nothing) until SendMessage
returns. This is not a case of the thread going too fast. The threads were
not synchronized.
quote:

Because posting a message doesn't require the message to be
processed before the thread moves on, this is the inherent
danger of posting IMO.


That's an advantage not a disadvantage.
quote:

The use of SendMessage forces a context switch so you have more
control.


Sorry, but that just ain't so. As soon as you use SendMessage between two
threads, you have lost control. If the receiving thread hangs, the sender will
never wake up. You want control, use SendMessageTimeout.

------------------
Dominic Mitchell

IP: Logged

Michael Mattias
Member
posted March 07, 2004 09:33 AM     Click Here to See the Profile for Michael Mattias     Edit/Delete Message   Reply w/Quote
GetQueueStatus is the call I could not find. Thank you.

IP: Logged


This topic is 2 pages long:   1  2 

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c