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 

get time problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Alex Liu
Guest





PostPosted: Wed Mar 30, 2005 2:19 am    Post subject: get time problem Reply with quote



Hi,

I am writing a multi-threaded time-critical application in which every
thread will write some logs to a log file. I defined a global function to
write logs in this way:

void __fastcall TGlobal::WriteLog(AnsiString msg)
{
CriticalSection->Enter();
try
{
mylogfile->Write(FormatDateTime("hh:nn:ss.zzz", Now()), msg);
}
__finally
{
CriticalSection->Leave();
}
}

And generally my threads work in this way:

while(!Terminated)
{
MyGlobal->WriteLog("thread start job");
dosomefcn();

MyGlobal->WriteLog("thread finish job");
Sleep(1);
}

where MyGlobal is passed as a reference, inited globally.

Here is the strange part (well, I feel it strange). The log shows time like
this:
14:37:01.984 thread_A start job
14:37:01.984 thread_A finish job
14:37:01.984 thread_B start job
14:37:01.984 thread_B finish job
14:37:01.984 thread_C start job
14:37:01.984 thread_C finish job
14:37:02.312 thread_A start job
14:37:02.312 thread_A finish job
14:37:02.312 thread_A start job
14:37:02.312 thread_A finish job
14:37:02.312 thread_B start job
14:37:02.312 thread_B finish job
14:37:02.312 thread_B start job
14:37:02.312 thread_B finish job
14:37:02.328 thread_C start job
14:37:02.328 thread_C finish job
14:37:02.343 thread_A start job
14:37:02.343 thread_A finish job
14:37:02.343 thread_A start job
14:37:02.343 thread_A finish job
14:37:02.343 thread_B start job
14:37:02.343 thread_B finish job
14:37:02.343 thread_B start job
14:37:02.343 thread_B finish job
14:37:02.359 thread_C start job

I feel strange that the time is the same for a period of time and over and
over again. Is this normal?
And i found that the time difference is always about 0.016s. Why? (this
confused me a lot as i cant accurately measure time used for a function)
Does it exist a more accurate way to log the time to milliseconds?

Thanks in advance.

Alex


Back to top
Andrue Cope [TeamB]
Guest





PostPosted: Wed Mar 30, 2005 8:12 am    Post subject: Re: get time problem Reply with quote



Alex Liu wrote:

Quote:
And i found that the time difference is always about 0.016s. Why?
(this confused me a lot as i cant accurately measure time used for a
function) Does it exist a more accurate way to log the time to
milliseconds?

This is not a C++ language issue. Ask in the .nativeapi section.

--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) 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.