[Lazarus] making multithreading more user friendly

Giuliano Colla giuliano.colla at fastwebnet.it
Sat Apr 28 11:43:31 CEST 2012


Il 28/04/2012 10:21, Mattias Gaertner ha scritto:
> On Sat, 28 Apr 2012 01:24:03 +0200
> Giuliano Colla<giuliano.colla at fastwebnet.it>  wrote:
>
> [...]
>> I could provide a patch if pointed to the right area of code to deal
>> with. IDE things remain a big mystery to me.
> AFAIK the real pain is to find the cause of the strange/misleading
> error messages. The remedy itself is pretty simple (a flag or a tiny
> code change).
>

The problem arises from TThread being in fpc rtl, which is of course 
unaware of Lazarus needs.
In Customdrawn, where I experimented a separate thread for timer events, 
it's been quite easy to add a clear error message if threading is not 
enabled:

constructor TCDX11TimerThread.Create(CreateSuspended: Boolean;
   const StackSize: SizeUInt);
var
   thisTM: TThreadManager;
begin
   GetThreadManager(thisTM);
   if not Assigned(thisTM.InitManager) then begin
     Raise Exception.Create
     ('You must define UseCThread (-dUseCThreads in Project Options->  Compiler Options) in order to run this program!');
     end;
   inherited Create (CreateSuspended);
   [..]

A LazThread class defined in LCL which wraps  TThread and performs 
appropriate checks could be a solution?

Giuliano





More information about the Lazarus mailing list