BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sleep works differently between Win2K and XP

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Compatibility with MFC)
View previous topic :: View next topic  
Author Message
Andy Scarle
Guest





PostPosted: Thu Nov 02, 2006 9:10 am    Post subject: Sleep works differently between Win2K and XP Reply with quote



I've an application written in C++ (BCB 6) which has a timer thread. I de-schedule this thread with a Sleep(1) to allow other parts of the application to run. (Using Sleep(0) just caused the thread to be re-entered immediately). Up to now this has been developed and run on Windows2000 machines. I've recently tried to migrate this to a Windows XP machine but the Sleep call seems to cause the rest of the application (the display) to lock up. I've tried Sleep with 0, 1 and 100 as parameters, all with the same effect. The rest of the application only runs if the Sleep is now commented out. Does anyone know any differences between 2000 and XP that could accunt for this (and better still any solution)?
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Nov 02, 2006 4:06 pm    Post subject: Re: Sleep works differently between Win2K and XP Reply with quote



"Andy Scarle" <andy.scarle (AT) mbda (DOT) co.uk> wrote in message
news:4549b1bd$1 (AT) newsgroups (DOT) borland.com...

Quote:
Using Sleep(0) just caused the thread to be re-entered immediately

Then you don't have any other threads running that are waiting for their own
time slices to become available.

Quote:
I've recently tried to migrate this to a Windows XP machine but the
Sleep call seems to cause the rest of the application (the display) to
lock up.


Calling Sleep() in a worker thread will not do that. Something else has to
be happening.

Quote:
The rest of the application only runs if the Sleep is now commented out.

Please show your actual code.


Gambit
Back to top
Andy Scarle
Guest





PostPosted: Fri Nov 03, 2006 9:10 am    Post subject: Re: Sleep works differently between Win2K and XP Reply with quote



In part of my application I want to check and process messages from an I/O board every millisecond so I change the tick rate to be a millisecond, and then have a Sleep in the timer thread to let the display/keyboard/mouse get a look-in.


First off I set up a fast tickrate for the system using:-

....
// Get current system time - just for a check in debugging
GetSystemTimeAdjustment( &adjustment,
&clockInterval,
&adjustmentDisabled );

// Adjust the timer tick to be 1mS (10000 * 100nS)
if( SetSystemTimeAdjustment( 10000, FALSE ) == 0 )
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, (void *)0, GetLastError(), 0, tempstr, 128, (const int

*)0 ) ;

MessageDlg( tempstr,
mtWarning,
TMsgDlgButtons() << mbOK,
0);
}

// Get current system time - just for a check in debugging
GetSystemTimeAdjustment( &adjustment,
&clockInterval,
&adjustmentDisabled );
}

if( timeBeginPeriod( 1 ) == TIMERR_NOCANDO )
{
MessageDlg("Timer Resolution setting - failed",
mtWarning,
TMsgDlgButtons() << mbOK,
0);
}
}


and start my timer thread with, (which is called as part of the FormCreate callback for the main applications form):-


Th = new TTestTimerThread(true) ;
Th->Resume() ;


the main bits of the timer thread is:-

// -----------------------------------------------------------------------------
void __fastcall TTestTimerThread::DoIt(void)
{

inTime = timeGetTime() ;
lastTime = inTime ;

// set some flags based on the timer
......


// call a couple of routines to check an I/O boards status
......

Sleep(1) ;
}

// -----------------------------------------------------------------------------
void __fastcall TTestTimerThread::Execute(void)
{
bool infinite ;

infinite = true ;
while(infinite)
{
Synchronize( DoIt ) ;

if(Terminated == true)
{
infinite = false ;
return;
}
}
}
//---------------------------------------------------------------------------
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Nov 03, 2006 4:44 pm    Post subject: Re: Sleep works differently between Win2K and XP Reply with quote

"Andy Scarle" <andy.scarle (AT) mbda (DOT) co.uk> wrote in message
news:454af937$1 (AT) newsgroups (DOT) borland.com...

Quote:
In part of my application I want to check and process messages
from an I/O board every millisecond so I change the tick rate to
be a millisecond, and then have a Sleep in the timer thread to let
the display/keyboard/mouse get a look-in.

Rather than using Sleep() in a loop, try using timeSetEvent() instead. It
runs a hig-speed multimedia timer thread.

Quote:
MessageDlg( tempstr,

MessageDlg() is not thread-safe, as it displays a VCL TForm. Use the API
MessageBox() instead.

Quote:
bool infinite ;

Why bother with that variable? Just use the Terminated property directly
instead, ie:

while( !Terminated )

Quote:
Synchronize( DoIt ) ;

Well, no wonder your code is so slow. Get rid of the Synchronize(). That
is forcing the bulk of your thread code to run in the context of the main
thread, which defeats the purpose of using a worker thread at all.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Compatibility with MFC) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.