[Lazarus] Lazarus implementation of TListView etc?
Bo Berglund
bo.berglund at gmail.com
Sat Oct 31 13:07:19 CET 2015
On Sat, 31 Oct 2015 10:22:08 +0000, Mark Morgan Lloyd
<markMLl.lazarus at telemetry.co.uk> wrote:
>Bo Berglund wrote:
>What does the main thread do? If you can contrive to write that as a
>loop, then as you've already been told you can call CheckSynchronize()
>which hands control to whatever's been queued by threads using
>Synchronize().
Right now the main thread (you mean the program code itself in the
console program DoRun event, right) does this (mostly debug messages
into the console):
procedure TIndyTCPtest.DoRun;
var
ErrorMsg: String;
FComm: TSockReadThread;
begin
FTerminated := false;
{ add your program here }
try
T1 := GetTickCount64;
Writeln('Creating TCP client');
FComm := TSockReadThread.Create('www.sunet.se', 80);
FComm.OnConnected := @OnConnect;
FComm.OnDisconnected := @OnDisConnect;
Fcomm.OnData := @OnRxData;
FComm.OnError := @OnError;
FComm.OnTerminate := @OnTerminate;
T2 := GetTickCount64;
Writeln('Start communications at time ' + IntToStr(T2-T1));
FComm.Start;
Writeln('Connecting to www.sunet.se on port 80');
T2 := GetTickCount64;
Writeln('Going to sleep 500 at time ' + IntToStr(T2-T1));
Sleep(500);
T2 := GetTickCount64;
Writeln('Waking up from sleep 500, at time ' + IntToStr(T2-T1));
T2 := GetTickCount64;
Writeln('Going to sleep 300 at time ' + IntToStr(T2-T1));
Sleep(300);
T2 := GetTickCount64;
Writeln('Waking up from sleep 300 at time ' + IntToStr(T2-T1));
Writeln('Terminating thread');
FComm.Terminate;
T2 := GetTickCount64;
Writeln('Freeing FComm at time ' + IntToStr(T2-T1));
finally
FComm.Free;
end;
// stop program loop
Terminate;
end;
And the output into the console is this:
Creating TCP client
Start communications at time 27
Connecting to www.sunet.se on port 80
Going to sleep 500 at time 27
Event: Socket connected! Time = 71 ms
Waking up from sleep 500, at time 527
Going to sleep 300 at time 527
Waking up from sleep 300 at time 827
Terminating thread
Freeing FComm at time 827
When I run it in Lazarus there is a pop-up window saying:
Project IndyTCPtest raised exception class 'External: SIGSEGV'.
At address 3132
>Depending on exactly what the program does, you might need to do
I just wanted to make a test with the TThread child I created, which
also contains the TIdTcpClient object, to see if the events fire off.
But I only get a single one into my code, then the SIGSEGV error.
>something like fudging keyboard access using fpSelect(), but basically
>it works... I've got a mainframe emulator here which responds to
>keyboard commands and also interleaves output from the various backend
>processes, I've used Lazarus as the IDE but it's entirely a console app.
I will have to figure out a way to make the test code do that loop. I
had hoped that while executing sleep() statements the main thread
would yield to the TCP thread but it seems like it does not...
>> I cannot use Synchronize because then the events fire off only when
>> the main program code ends and if I don't use Synchronize then I get a
>> SIGSEG exception somewhere.
>
>Assume that none of the LCL is thread-safe, i.e. background threads have
>no safe UI access. Assume that the RTL and FCL are not specifically
>thread safe except where documented, but that you can use it in
>conjunction with conventional "cautious" programming techniques.
I have assumed as much so there is no side access to any data as far
as I can tell.
Again, this is just a very simple console test program to check the
operations of the threaded TCPIP communications, nothing near the
final code because there I will have exit conditions and such.
--
Bo Berglund
Developer in Sweden
More information about the Lazarus
mailing list