[fpc-pascal] Correct way for using TThread.ForceQueue?

Thomas Kurz fpc.2021 at t-net.ruhr
Mon Apr 25 16:38:37 CEST 2022


This is a very elegant solution but it can only be used for Synchronize, right? Because with ForceQueue I cannot know when it's done and freeing within Run (i.e. "Self.Free") would fail.

Using an advanced record would be fine, but it doesn't fit the declaration "TThreadMethod = procedure of object".



----- Original Message ----- 
From: Mattias Gaertner via fpc-pascal <fpc-pascal at lists.freepascal.org>
To: fpc-pascal at lists.freepascal.org <fpc-pascal at lists.freepascal.org>
Sent: Monday, April 25, 2022, 16:12:40
Subject: [fpc-pascal] Correct way for using TThread.ForceQueue?

On Mon, 25 Apr 2022 15:47:57 +0200
Thomas Kurz via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:

>[...]
> As far as I have seen so far, the common solution is to use a
> variable inside the class to cache the parameters, then to use a
> DoCallSync procedure which takes no parameters but can use the cached
> values inside, and finally to call TThread.Synchronize(NIL,
> @DoCallSync). I have stick to this concept when using Synchronize,
> too.

Or some small class:

type
  TMyData = class 
    a: whatever;
    procedure Run;
  end;

MyData:=TMyData.Create;
MyData.a:=...;
TThread.Synchronize(NIL, @MyData.Run).

Free MyData when done and/or in the destructor.

 
>[...]

Mattias
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list