[Lazarus] AsyncProcess code problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] AsyncProcess code problem

Free Pascal - Lazarus mailing list
Having a problem with some code here :)

Lazarus 1.9.0 r55266M FPC 3.1.1 x86_64-linux-gtk2

I create a thread every second to run a process (TAsyncprocess), then
FreeAndNil the process once done.

My app aborts regularly (though intermittently) with the following from gdb.

My question is about the fact of 'appprocessmessages' being in the fault
path.

Is this normal for a threaded call to TAsyncProc, or have I introduced
my own fault ?.

I dont have any main thread/gui accessing calls from within my created
thread.

Thread 1 "LxAazCMA" received signal SIGSEGV, Segmentation fault.
0x00007fffef6eddb4 in REMOVEEVENTHANDLER (this=0xf9efb8, AHANDLER=0x0)
at gtk2/gtk2lclintf.inc:1355
1355      if lEventHandler^.PrevHandler = nil then

(gdb) bt
#0  0x00007fffef6eddb4 in REMOVEEVENTHANDLER (this=0xf9efb8,
AHANDLER=0x0) at gtk2/gtk2lclintf.inc:1355
#1  0x00007fffef6ee022 in REMOVEPIPEEVENTHANDLER (this=0xf9efb8,
AHANDLER=0x0) at gtk2/gtk2lclintf.inc:1429
#2  0x00007fffef7af46d in REMOVEPIPEEVENTHANDLER (AHANDLER=0x0) at
include/lclintf.inc:424
#3  0x00007fffef9beeba in UNHOOKPIPEHANDLE (this=0x7fffd4013608) at
asyncprocess.pp:84
#4  0x00007fffef9beee5 in HANDLEPIPEINPUT (this=0x7fffd4013608, ADATA=0,
AREASONS=...) at asyncprocess.pp:90
#5  0x00007fffef6edfe2 in HANDLEPIPEEVENT (this=0xf9efb8,
ADATA=140736750234040, AFLAGS=17)
     at gtk2/gtk2lclintf.inc:1421
#6  0x00007fffef6edc5d in WAITHANDLE_IOCALLBACK (SOURCE=0x7fffd4028570,
CONDITION=17, DATA=0x7fffd40128d8)
     at gtk2/gtk2lclintf.inc:1318
#7  0x00007ffff664004a in g_main_context_dispatch () from
/lib/x86_64-linux-gnu/libglib-2.0.so.0
#8  0x00007ffff66403f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#9  0x00007ffff664049c in g_main_context_iteration () from
/lib/x86_64-linux-gnu/libglib-2.0.so.0
#10 0x000000000054d9c9 in APPPROCESSMESSAGES (this=0xe9bcb8) at
gtk2/gtk2widgetset.inc:2338
#11 0x000000000045a27d in HANDLEMESSAGE (this=0xe99908) at
include/application.inc:1276
#12 0x000000000045a7af in RUNLOOP (this=0xe99908) at
include/application.inc:1413
#13 0x00000000006a0673 in APPRUN (this=0xe9bcb8, ALOOP=...) at
include/interfacebase.inc:54
#14 0x000000000045a74f in RUN (this=0xe99908) at
include/application.inc:1401
#15 0x000000000041ea25 in main () at LynxApp.lpr:82
(gdb)

Thanks - SteveG

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] AsyncProcess code problem

Free Pascal - Lazarus mailing list
On Fri, 9 Jun 2017 17:08:25 +0930
Steve Gatenby via Lazarus <[hidden email]> wrote:

> Having a problem with some code here :)
>
> Lazarus 1.9.0 r55266M FPC 3.1.1 x86_64-linux-gtk2
>
> I create a thread every second to run a process (TAsyncprocess), then
> FreeAndNil the process once done.

If you are using threads, then why use TAsyncProcess?
TAsyncProcess was invented as a non blocking TProcess for the main
thread.
Probably it can be made thread safe for the gtk2 interface, but
if you already use threads, then you can simply use TProcess or
TProcessUTF8 with less overhead.


Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] AsyncProcess code problem

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 09.06.2017 09:38, Steve Gatenby via Lazarus wrote:
>
> I create a thread every second to run a process (TAsyncprocess), then
> FreeAndNil the process once done.
>

Would it not be more appropriate to use a thread pool and keep the
threads up, waiting for a TEvent telling them what to do ?

-Michael
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] AsyncProcess code problem

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


On 06/09/2017 05:32 PM, Mattias Gaertner via Lazarus wrote:

> On Fri, 9 Jun 2017 17:08:25 +0930
> Steve Gatenby via Lazarus <[hidden email]> wrote:
>
>> Having a problem with some code here :)
>>
>> Lazarus 1.9.0 r55266M FPC 3.1.1 x86_64-linux-gtk2
>>
>> I create a thread every second to run a process (TAsyncprocess), then
>> FreeAndNil the process once done.
> If you are using threads, then why use TAsyncProcess?
> TAsyncProcess was invented as a non blocking TProcess for the main
> thread.
> Probably it can be made thread safe for the gtk2 interface, but
> if you already use threads, then you can simply use TProcess or
> TProcessUTF8 with less overhead.
>
>
> Mattias
Thanks Mattias - I will change to TProcess and see how it goes.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] AsyncProcess code problem

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 06/09/2017 05:42 PM, Michael Schnell via Lazarus wrote:

> On 09.06.2017 09:38, Steve Gatenby via Lazarus wrote:
>>
>> I create a thread every second to run a process (TAsyncprocess), then
>> FreeAndNil the process once done.
>>
>
> Would it not be more appropriate to use a thread pool and keep the
> threads up, waiting for a TEvent telling them what to do ?
>
> -Michael
I have been meaning to do so, and now seems a good time to refactor it all.
I will add this to using TProcess on Mattias's suggestion

Thank you
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus