[M3devel] question on use of Time.Now in thread test program
Jay K
jay.krell at cornell.edu
Tue Mar 15 00:07:15 CET 2011
Time.Now() is very cheap on Windows and should cause no concern.
It is just GetSystemTimeAsFileTime, which just reads some globals, followed by a simple unit and integer to double conversion.
I would avoid 64bit Windows for now, very unfortunate, but I don't trust GetThreadContext.
PROCEDURE Now(): T=
VAR
fileTime: WinBase.FILETIME;
BEGIN
WinBase.GetSystemTimeAsFileTime(fileTime);
RETURN TimeWin32.FromFileTime(fileTime);
END Now;
double
__cdecl
TimeWin32__FromFileTime(FILETIME ft)
{
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
return ((double)li.QuadPart) / 1.0e7;
}
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.
Maybe code the entire thing in Modula-3 -- or more likely, the entire thing in C.
Time.Now() might be more expensive on other platform, I don't know.
I also see some failures, some success, no pattern.
I think the success is just luck and the code is by its nature very non-deterministic.
- Jay
From: rcolebur at SCIRES.COM
To: m3devel at elegosoft.com
Date: Mon, 14 Mar 2011 18:45:44 -0400
Subject: [M3devel] question on use of Time.Now in thread test program
I have a question/concern regarding Mika’s thread test program.
Each of the threads makes use of the Time.Now() call during each iteration of the thread’s main loop.
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?
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.
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().
I will also try to experiment with Windows XP 32-bit and report back.
Regards,
Randy Coleburn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20110314/b0dca15e/attachment-0002.html>
More information about the M3devel
mailing list