Thread synchronization is not possible with TDaemon for Windows
Original Reporter info from Mantis: halmariane
-
Reporter name:
Original Reporter info from Mantis: halmariane
- Reporter name:
Description:
Thread synchronization is not possible with TDaemon for Windows Operating Systems. The same code works fine for Linux.
When the same code is compiled from Delphi then Works fine as Lazarus for Linux.
Delphi (Windows) = Works!
Lazarus (Linux) = Works!
Lazarus (Windows) = Fail!
Steps to reproduce:
// Sample Code
// ***********
// In this sample code, the methos "IntervalEvent" is never called with Lazarus
// for Windows
{ TSimpleDaemon }
procedure TSimpleDaemon.DataModuleCreate(Sender: TObject);
begin
Logger.LogType:=ltFile;
Logger.FileName:='c:\pp.log';
end;
procedure TSimpleDaemon.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);
begin
FSimpleThread:=TSimpleThread.Create(True);
FSimpleThread.OnInterval:=@IntervalEvent;
FSimpleThread.Start;
OK:=True;
end;
procedure TSimpleDaemon.DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);
begin
FSimpleThread.Terminate;
FSimpleThread.Free;
OK:=True;
end;
procedure TSimpleDaemon.IntervalEvent(Sender: TObject);
begin
Logger.Info('Log ' + IntToStr(FSimpleThread.Counter));
end;
{ TSimpleThread }
procedure TSimpleThread.Execute;
begin
while not Terminated do
begin
Sleep(3000);
Inc(FCounter);
if Assigned(FOnInterval) then
Synchronize(@CallOnInterval);
end;
end;
procedure TSimpleThread.CallOnInterval;
begin
FOnInterval(Self);
end;
constructor TSimpleThread.Create(CreateSuspended: Boolean;
const StackSize: SizeUInt);
begin
inherited;
FCounter:=0;
end;
Additional information:
Dropped components that requires this type of Synchronization do not work.
Mantis conversion info:
- Mantis ID: 24511
- OS: Windows
- OS Build: Any
- Build: Lazarus SVN 40788
- Platform: x86 / 32 - 64
- Version: 1.1 (SVN)
- Monitored by: » papelhigienico (Fabio Luis Girardi), » bpascalblockchain@gmail.com (Albert Molina)