[Lazarus] Tracking down an intermittent termination exception
Sven Barth
pascaldragon at googlemail.com
Tue Mar 26 13:40:43 CET 2013
Am 26.03.2013 12:16 schrieb "Mark Morgan Lloyd" <
markMLl.lazarus at telemetry.co.uk>:
>
> Sven Barth wrote:
>
>>> DoneCriticalSection(SynchronizeCritSect);
>>>
>>> Assuming that this is a problem in my own code, what sort of thing
should I be looking for?
>>
>>
>> After looking through the following things:
>>
>> - code of CDoneCriticalSection (in rtl/unix/cthreads.pp)
>> - man page of pthread_mutex_destroy
>> - code of fpc_threaderror (in rtl/inc/system.inc)
>> - code of RunErrorToExcept (in rtl/objpas/sysutils/sysutils.inc)
>>
>> the most valid assumption is that the critical section is destroyed
while it's in use. As this critical section is only used inside a
Synchronize call from a thread (the mainthread will directly call the
method without any locking) it seems that your background thread is inside
a Synchronize call when you terminate your application.
>
>
> Synchronize() is only used for message display, the program's silent
until it sees TCP traffic. From what you're saying I suspect that it's
probably caused by the socket the thread's waiting on being forcibly
closed, at which point the thread tries to display a message.
>
Yes, that could he the problem then.
>> Solution: Tell the thread to terminate (if you use the thread's
Terminate property you'll need to check this inside your thread's loop) and
then wait for (TThread.WaitFor) it to finish before you continue with
termination. This will also ensure that any cleanup that is done inside the
thread is finished before the RTL is finalized.
>
>
> Thanks Sven, I'll dig. At present the background thread is watching for
the main thread to start terminating as a stimulus for it to fall through
the main loop, is there a wiki page or an example somewhere showing "best
practice" for this sort of thing?
>
I don't know whether there is something like that... :(
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130326/3891caae/attachment-0003.html>
More information about the Lazarus
mailing list