[fpc-devel] TThread.RemoveQueuedEvents

Martin Frb lazarus at mfriebe.de
Sat Sep 26 14:02:36 CEST 2020


On 26/09/2020 13:35, Martin Frb via fpc-devel wrote:
> Unfortunately I do not have Delphi.
> Can anyone test this?

I made a test program

If it does not print any "in foo" then it ignores the instance.
Otherwise it should print one "in foo".

Besides of "what Delphi does", what would anyone expect from reading the 
code?



program Project1;
{$mode objfpc}{$H+}
uses
   {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes;

type
   TMyClass = class
     procedure Foo;
   end;

   TMyThread = class(TThread)
   public
     procedure Execute; override;
   end;
var
   i: integer;

procedure TMyThread.Execute;
var
   c1, c2: TMyClass;
begin
   c1 := TMyClass.Create;
   c2 := TMyClass.Create;
   Queue(self, @c1.Foo);
   Queue(self, @c2.Foo);
   RemoveQueuedEvents(Self, @c1.Foo);
   inc(i);
end;

procedure TMyClass.Foo;
begin
   writeln('In Foo');
end;

begin
   i := 0;
   TMyThread.Create(False);
   while i = 0 do ;
   CheckSynchronize();
   writeln('Did we get one or none "In Foo"');
   ReadLn;
end.



More information about the fpc-devel mailing list