<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Time.Now() is very cheap on Windows and should cause no concern.<BR>
It is just GetSystemTimeAsFileTime, which just reads some globals, followed by a simple unit and integer to double conversion.<BR>
I would avoid 64bit Windows for now, very unfortunate, but I don't trust GetThreadContext.<BR>
<BR>
<BR>
PROCEDURE Now(): T=<BR> VAR<BR> fileTime: WinBase.FILETIME;<BR> BEGIN<BR> WinBase.GetSystemTimeAsFileTime(fileTime);<BR> RETURN TimeWin32.FromFileTime(fileTime);<BR> END Now;<BR><BR><BR>
double<BR>__cdecl<BR>TimeWin32__FromFileTime(FILETIME ft)<BR>{<BR> LARGE_INTEGER li;<BR><BR> li.LowPart = ft.dwLowDateTime;<BR> li.HighPart = ft.dwHighDateTime;<BR> return ((double)li.QuadPart) / 1.0e7;<BR>}<BR><BR><BR>
Hm -- I don't like passing structs by value, too hard to be sure how it works -- I'd like to change this to be "READONLY" -- passed by pointer.<BR>
Maybe code the entire thing in Modula-3 -- or more likely, the entire thing in C.<BR>
<BR>
Time.Now() might be more expensive on other platform, I don't know.<BR>
<BR>
I also see some failures, some success, no pattern.<BR>
I think the success is just luck and the code is by its nature very non-deterministic.<BR>
<BR>
- Jay<BR> <BR>
<HR id=stopSpelling>
From: rcolebur@SCIRES.COM<BR>To: m3devel@elegosoft.com<BR>Date: Mon, 14 Mar 2011 18:45:44 -0400<BR>Subject: [M3devel] question on use of Time.Now in thread test program<BR><BR>
<META name=Generator content="Microsoft SafeHTML">
<STYLE>
.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal
{margin-bottom:.0001pt;font-size:11.0pt;font-family:'Calibri','sans-serif';}
.ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass a:visited, .ExternalClass span.ecxMsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
.ExternalClass span.ecxEmailStyle17
{font-family:'Calibri','sans-serif';color:windowtext;}
.ExternalClass .ecxMsoChpDefault
{;}
@page WordSection1
{size:8.5in 11.0in;}
.ExternalClass div.ecxWordSection1
{page:WordSection1;}
</STYLE>
<DIV class=ecxWordSection1>
<P class=ecxMsoNormal>I have a question/concern regarding Mika’s thread test program.</P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>Each of the threads makes use of the Time.Now() call during each iteration of the thread’s main loop. </P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>I haven’t fully investigated, but does anyone have concern that so many calls to the system clock from multiple competing threads might have some side effect on the running of multiple threads?</P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>I’ve also done some limited experimentation with use of counters to see how many times each type of thread is able to go thru its loop between reporting intervals.</P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>I continue to see various types of crashes on Windows 7 (64-bit), but sometimes tests are able to succeed. I haven’t found a repeatable pattern yet to the crashes, so I am still investigating, but just thought it worth asking the above question about use of Time.Now().</P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>I will also try to experiment with Windows XP 32-bit and report back.</P>
<P class=ecxMsoNormal> </P>
<P class=ecxMsoNormal>Regards,</P>
<P class=ecxMsoNormal>Randy Coleburn</P></DIV> </body>
</html>