Recent

Author Topic: GetTickCount  (Read 6656 times)

JimKueneman

  • Full Member
  • ***
  • Posts: 220
GetTickCount
« on: December 20, 2012, 02:55:21 am »
I am using this in a thread:

Result := LclIntf.GetTickCount
 
which at the end of the day calls this:

fpgettimeofday(@tp, nil);   

and it is crashing the application.  Should this be thread safe?

OSX Lion

Thanks,
Jim






User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: GetTickCount
« Reply #1 on: December 20, 2012, 05:05:23 am »
Does the variable "tp" belong to the thread, or is it public variable that many threads could send same time?

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: GetTickCount
« Reply #2 on: December 20, 2012, 06:26:59 am »
What kind of type is your Result? I had this same issue. GetTickCount return DWord and my variable was Integer. Make sure that you are using Dword

JimKueneman

  • Full Member
  • ***
  • Posts: 220
Re: GetTickCount
« Reply #3 on: December 20, 2012, 02:43:29 pm »
Quote
Does the variable "tp" belong to the thread, or is it public variable that many threads could send same time?


It is created and used within the thread function.

Quote
What kind of type is your Result? I had this same issue. GetTickCount return DWord and my variable was Integer. Make sure that you are using Dword

As seen below it is a DWord.

Here is the real code.

This is in a TThread class in an overridden Execute method.

Code: [Select]
procedure TComPortThread.Execute;
var
  List: TList;
  ReceiveStr, SendStr: AnsiString;
  Helper: TOpenLCBMessageHelper;
  CompletedSendDatagram: TDatagramSend;
  T: DWord;  // Time the execution of the thread loop
begin
  T := 0;
  CompletedSendDatagram := nil;
  Helper := TOpenLCBMessageHelper.Create;
  Serial := TBlockSerial.Create;                           // Create the Serial object in the context of the thread
  Serial.LinuxLock:=False;
  Serial.RaiseExcept:=False;
  Serial.Connect(Port);
  try
    if Serial.InstanceActive then
    begin
      Connected:=True;
      Serial.Config(BaudRate, 8, 'N', 0, False, False);      // FTDI Driver uses no stop bits for non-standard baud rates.
      while not Terminated do
      begin
        ThreadSwitch;             // Let main thread have some time
        T := GetTickCount;   
         ...
« Last Edit: December 20, 2012, 02:45:00 pm by JimKueneman »

JimKueneman

  • Full Member
  • ***
  • Posts: 220
Re: GetTickCount
« Reply #4 on: December 20, 2012, 02:59:54 pm »
Hold the phone.... I am using this to time the loop:

I time the loop then store the delta T in property of the class.  I then have some debug code that writes this to a form (yes I know accessing a form from a thread is bad but this is only for testing).  If I don't write to the form it works fine.  If I do write to the form it crashes.  I don't understand why I am using other properties to update this form...

I guess I see what is crashing, just need to see why.  It is not the call to GetTickCount directly.

Jim

 

TinyPortal © 2005-2018