Just an idea...
I know you are coding in Lazarus - but Lazarus - even simplified adds
layers of stuff - is there anyway you can make your core functionality
reside in a UNIT - and then make a console app test application that
puts it through its paces.... then if it works - link it in to your
"Lazarus GUI in Development" ?
I also see potential issue here:
Begin ---- Snippet
procedure TForm1.testTerminate(Sender: TObject);
begin
if (sender is ttestthread) then
memo1.lines.add(ttestthread(sender).result);
end;
End ---- Snippet
I recommend you create a CriticalSection or figure out how to do the
other "faster" thread-to-thread sync for that code snippet.
I personally don't find critical sections cause me contention if I use
them sparingly and make sure that where I use them can't cause thread
locking by stacking up "waiting" dependencies if you know what I mean -
(One thread stuck, because another thread needs too.. but can't because
that first thread must do ?? first) I hope you know what I mean.
For example... I make a few key critical sections when my multi-threaded
apps start. One is specifically for that freepascal "filemode" global
flag I spoke of in the first email. My code is pretty simple handling
these things because I try to keep the complex stuff lean and made easy
to debug because threading can turn into a nightmare!
This snippet shows my critical sections being declared in my thread
manager unit.
Begin----Code sample
//=============================================================================
// Multi-threading considerations
//=============================================================================
{}
var
CSECTION_INTERTHREAD_MAINPROCESS: TCriticalSection;
CSECTION_INTERTHREAD: TCriticalSection;
CSECTION_MAINPROCESS: TCriticalSection;
CSECTION_FILEREADMODEFLAG: TCriticalSection;
MAINJTMSGFIFO: JFC_FIFO;
MAINChildren: JFC_DL;
{}
// TCriticalSection in syncobjs unit.
// Create, Destroy. Enter, Leave.
{}
procedure InitThreadManager(p_rThreadManagerInit:rtThreadManagerInit);
procedure DoneThreadManager;
//=============================================================================
End----Code sample
A sample of using the filemode critical section might shed some light on
how to handle that bit of code with the memo text area or list you are
putting data in your lazarus gui.
Begin----Code Snippet
safilename:=grJASCOnfig.saLogDir +
'TJTHREAD_'+inttostr(cardinal(self))+'.txt';
try
CSECTION_FILEREADMODEFLAG.Enter;
FileMode:=READ_WRITE;
{$I-}
assign(f,safilename);
if(fileexists(safilename)) then append(f) else rewrite(f);
{$I+}
finally
CSECTION_FILEREADMODEFLAG.leave;
end;
// Don't really care if something changes the FILEMODE flag now
because my file is open in the mode I want
// Of course I could add better IO handling here - like messing with
IORESULT... which is again
// another FREEPASCAL global needing the same special attention. So,
because I don't want a huge bottle
// neck accessing files - I limit the critical bit for the flag switch
and the file open.
// I'm sure there is a better way - but this technique has solved many
headaches.
{$I-}
writeln(f,p_i8Code,'
',saDebugNest(p_saFunction,true,self.iNestLevel),' ',p_saSourcefile);
close(f);
{$I+}
End------Code Snippet
--Jason P Sage
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public