Jump to content

TThreads doesn't work correctly with Delphi/Linux


Tokay

Recommended Posts

unit Main; //Delphi code

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniGUIBaseClasses, uniButton;

type
  TTestThread = class(TThread)
   protected
     procedure Execute; override;
  end;

  TMainForm = class(TUniForm)
    UniButton1: TUniButton;
    procedure UniButton1Click(Sender: TObject);
  private
    { Private declarations }
   FThread: TTestThread;
   procedure OnTerminate(Sender: TObject);
  public
    { Public declarations }
  end;


function MainForm: TMainForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication;

function MainForm: TMainForm;
begin
  Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;

procedure TMainForm.OnTerminate(Sender: TObject);
begin
 Sleep(1); //(2)
end;

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
 FThread := TTestThread.Create(True);
 FThread.OnTerminate := OnTerminate;
 FThread.Start;
end;

{ TTestThread }

procedure TTestThread.Execute;
begin
  inherited;
  Sleep(1); //(1)
end;

initialization
  RegisterAppFormClass(TMainForm);

end.

This is the test code. For testing just set break points on the both sleeps. Under windows all works fine: after starting and push the button sleep (1) is activated, then sleep (2). But under Linux sleep (2) doesn't fired at all. In the Lazarus/FPC I fixed the issue with call of CheckSynchronize, but I have no Core sources, and could not run CheckSynchronize synchronously  and projects doesn't works. It's critical behavior for our projects! Please, get a look, how is it possible to fix an issue?

procedure TService.ManageDaemon; //FPC code
begin
 DoStart;
 repeat
  if FDoTerm then
   Break
  else
   { wait a while }
   Sleep(50);
  CheckSynchronize;
 until FDoTerm;
 DoStop;
end;


 

 

Link to comment
Share on other sites

3 hours ago, Farshad Mohajeri said:

What is your Delphi version?

Latest licensed 10.4.1 ARCHITECT with all patches:

Embarcadero® RAD Studio 10.4 Version 27.0.38860.1461 
Copyright © 2020 Embarcadero Technologies, Inc. All Rights Reserved.
 

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...