View Full Version : Problem with threads
Jonathan Neve[Microtec]
13-Oct-2005, 04:44 PM
Hi,
I've got the same trouble with threads as I reported previously... :-(
It only occurs using BCB 5. The trouble is that _in certain
circumstances_, an access violation is launched when an error occurs,
instead of the correct error being displayed.
Specifically, there is something in EL that seems to provoke FIBPlus
(which uses multiple threads), and causes strange access violations in
FIBPlus code, when in reality there was only an ordinary SQL error...
Fabio, I had thought this error had been fixed in 5.0.3, but it turns
out it's still there. I took the test case I had sent you and
recompiled it, and the error still occurs, even with 5.0.4. :-(
Were you ever able to reproduce this?
--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
admin
14-Oct-2005, 08:30 AM
Jonathan Neve[Microtec] wrote:
> Hi,
>
> I've got the same trouble with threads as I reported previously... :-(
>
> It only occurs using BCB 5. The trouble is that _in certain
> circumstances_, an access violation is launched when an error occurs,
> instead of the correct error being displayed.
>
> Specifically, there is something in EL that seems to provoke FIBPlus
> (which uses multiple threads), and causes strange access violations in
> FIBPlus code, when in reality there was only an ordinary SQL error...
>
> Fabio, I had thought this error had been fixed in 5.0.3, but it turns
> out it's still there. I took the test case I had sent you and
> recompiled it, and the error still occurs, even with 5.0.4. :-(
>
> Were you ever able to reproduce this?
It's really strange...
....but if you can tell to me what exactly I must do to reproduce it,
then I can assure to you to fix it shortly and definitely, ok? :)
I need your Firebird version, BCB Update Pack installed, Windows used, ...
PS: at this time I'm unsure if is an EL bug or not! ;)
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG showing line n.
Jonathan Neve[Microtec]
14-Oct-2005, 08:40 AM
admin wrote:
> Jonathan Neve[Microtec] wrote:
> > Hi,
> >
> > I've got the same trouble with threads as I reported previously...
> > :-(
> >
> > It only occurs using BCB 5. The trouble is that _in certain
> > circumstances_, an access violation is launched when an error
> > occurs, instead of the correct error being displayed.
> >
> > Specifically, there is something in EL that seems to provoke FIBPlus
> > (which uses multiple threads), and causes strange access violations
> > in FIBPlus code, when in reality there was only an ordinary SQL
> > error...
> >
> > Fabio, I had thought this error had been fixed in 5.0.3, but it
> > turns out it's still there. I took the test case I had sent you and
> > recompiled it, and the error still occurs, even with 5.0.4. :-(
> >
> > Were you ever able to reproduce this?
>
> It's really strange...
> ...but if you can tell to me what exactly I must do to reproduce it,
> then I can assure to you to fix it shortly and definitely, ok? :)
>
> I need your Firebird version, BCB Update Pack installed, Windows
> used, ...
Ok. I'm using IB 6.0, BCB 5 update 1, using linker patch for BCB 6, and
Windows XP SP2.
I tried my example project in Delphi 7, and it works fine, but in BCB
5, it doesn't...
Have you still got my test-case? If not, tell me and I'll send it
again. If you have it, try just recompiling it with BCB 5, and clicking
on the button: do you get the proper error message, or do you get an
access violation? When I activate EL in the project I get an access
violation (sometime followed by the real error message), otherwise I
get the real message.
> PS: at this time I'm unsure if is an EL bug or not! ;)
Yes, I will mention it to the FIBPlus team as well. The trouble is,
since it doesn't occur at all without EL, it's hard to get them to find
a bug in their code... :-(
--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
admin
14-Oct-2005, 10:23 AM
Jonathan Neve[Microtec] wrote:
> admin wrote:
>
>
>>Jonathan Neve[Microtec] wrote:
>>
>>>Hi,
>>>
>>>I've got the same trouble with threads as I reported previously...
>>>:-(
>>>
>>>It only occurs using BCB 5. The trouble is that _in certain
>>>circumstances_, an access violation is launched when an error
>>>occurs, instead of the correct error being displayed.
>>>
>>>Specifically, there is something in EL that seems to provoke FIBPlus
>>>(which uses multiple threads), and causes strange access violations
>>>in FIBPlus code, when in reality there was only an ordinary SQL
>>>error...
>>>
>>>Fabio, I had thought this error had been fixed in 5.0.3, but it
>>>turns out it's still there. I took the test case I had sent you and
>>>recompiled it, and the error still occurs, even with 5.0.4. :-(
>>>
>>>Were you ever able to reproduce this?
>>
>>It's really strange...
>>...but if you can tell to me what exactly I must do to reproduce it,
>>then I can assure to you to fix it shortly and definitely, ok? :)
>>
>>I need your Firebird version, BCB Update Pack installed, Windows
>>used, ...
>
>
> Ok. I'm using IB 6.0, BCB 5 update 1, using linker patch for BCB 6, and
> Windows XP SP2.
>
> I tried my example project in Delphi 7, and it works fine, but in BCB
> 5, it doesn't...
>
> Have you still got my test-case? If not, tell me and I'll send it
> again. If you have it, try just recompiling it with BCB 5, and clicking
> on the button: do you get the proper error message, or do you get an
> access violation? When I activate EL in the project I get an access
> violation (sometime followed by the real error message), otherwise I
> get the real message.
>
>
>>PS: at this time I'm unsure if is an EL bug or not! ;)
>
>
> Yes, I will mention it to the FIBPlus team as well. The trouble is,
> since it doesn't occur at all without EL, it's hard to get them to find
> a bug in their code... :-(
I have recompiled all, using the same your configuration.
But I have removed same libraries that I haven't.
The result it's really good! ;)
All works fine!
These are the original and the modified project options file (.BPR).
PS: I think that some of these libraries was in conflict with your
FIBPlus components suite! :)
Try to you and tell back to me your result, ok?
ORIGINAL:
--------------------------------------------------------------------
<PROJECT>
<MACROS>
<LIBRARIES value="FIBPlus625_CB5.lib E110_R51.lib TeeUI50.lib
TeeQR50.lib TeeDB50.lib Tee50.lib O308_R51.lib E108BR51.lib
QRPT50.lib VCLBDE50.lib S204_R51.lib VCLIB50.lib VCLDB50.lib
VCLX50.lib E108_R51.lib Vcl50.lib"/>
<SPARELIBS value="Vcl50.lib E108_R51.lib VCLX50.lib VCLDB50.lib
VCLIB50.lib S204_R51.lib VCLBDE50.lib QRPT50.lib E108BR51.lib
O308_R51.lib Tee50.lib TeeDB50.lib TeeQR50.lib TeeUI50.lib
E110_R51.lib FIBPlus625_CB5.lib"/>
</MACROS>
</PROJECT>
--------------------------------------------------------------------
MODIFIED:
--------------------------------------------------------------------
<PROJECT>
<MACROS>
<LIBRARIES value="FIBPlus625_CB5.lib TeeUI50.lib
TeeQR50.lib TeeDB50.lib Tee50.lib O308_R51.lib
QRPT50.lib VCLBDE50.lib VCLIB50.lib VCLDB50.lib
VCLX50.lib Vcl50.lib"/>
<SPARELIBS value="Vcl50.lib VCLX50.lib VCLDB50.lib
VCLIB50.lib VCLBDE50.lib QRPT50.lib
Tee50.lib TeeDB50.lib TeeQR50.lib TeeUI50.lib
FIBPlus625_CB5.lib"/>
</MACROS>
</PROJECT>
--------------------------------------------------------------------
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG showing line n.
Jonathan Neve[Microtec]
14-Oct-2005, 07:37 PM
It makes no difference for me...
However, I tried compiling FIBPlus without the FIBSQLMonitor, and it
works fine. Could you try recompiling FIBPlus with {$DEFINE NO_MONITOR}
in FIBPlus.inc, please?
I know this sounds like a FIBPlus bug, and then again, without EL, it
does work...
I'll continue testing and tell you the results.
--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
Jonathan Neve[Microtec]
14-Oct-2005, 07:37 PM
Hi Fabio!
Good news: I found a bug in FIBPlus, which was causing the error.
The cause is actually very simple: the FIBSQLMonitor writer thread has
a TList field that holds the list of messages. This TList is accessed
in the Execute method, and freed in the destructor of the thread.
The problem was, that AFTER freeing the TList, the destructor calls
"inherited Destroy", which in turn, contains the following code (from
Classes.pas):
destructor TThread.Destroy;
begin
if not FFinished and not Suspended then
begin
Terminate;
WaitFor;
end;
if FHandle <> 0 then CloseHandle(FHandle);
inherited Destroy;
RemoveThread;
end;
When the WaitFor was called, the Execute method of the thread was
called again, causing an invalid access of the TList, which had already
been freed.
So the moral of the story is, if you access fields from the Execute
method of your thread, be careful that they haven't already been freed
before using them, and use FreeAndNil in the destructor so that there
can be no doubt. I don't know why this error occurs only in BCB 5, nor
why it didn't occur with EurekaLog 4, but it seems to have a lot to do
with the timing of the threads, and so I suppose EL 5 changed something
in that respect.
Thanks a lot for your support Fabio!
--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
admin
14-Oct-2005, 07:37 PM
Hi Jonathan,
Jonathan Neve[Microtec] wrote:
> Hi Fabio!
>
> Good news: I found a bug in FIBPlus, which was causing the error.
>
> The cause is actually very simple: the FIBSQLMonitor writer thread has
> a TList field that holds the list of messages. This TList is accessed
> in the Execute method, and freed in the destructor of the thread.
>
> The problem was, that AFTER freeing the TList, the destructor calls
> "inherited Destroy", which in turn, contains the following code (from
> Classes.pas):
>
> destructor TThread.Destroy;
> begin
> if not FFinished and not Suspended then
> begin
> Terminate;
> WaitFor;
> end;
> if FHandle <> 0 then CloseHandle(FHandle);
> inherited Destroy;
> RemoveThread;
> end;
>
> When the WaitFor was called, the Execute method of the thread was
> called again, causing an invalid access of the TList, which had already
> been freed.
>
> So the moral of the story is, if you access fields from the Execute
> method of your thread, be careful that they haven't already been freed
> before using them, and use FreeAndNil in the destructor so that there
> can be no doubt. I don't know why this error occurs only in BCB 5, nor
> why it didn't occur with EurekaLog 4, but it seems to have a lot to do
> with the timing of the threads, and so I suppose EL 5 changed something
> in that respect.
>
> Thanks a lot for your support Fabio!
It's my job and I love it! ;)
In EurekaLog 5.x I have more potentially the threads exceptions
handling, so EurekaLog 5 catches the FIBSQLMonitor bug (in the thread)!
Have you just communicate to the FIBPlus authors about this bug and fix?
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG showing line n.
Jonathan Neve[Microtec]
14-Oct-2005, 07:37 PM
admin wrote:
> It's my job and I love it! ;)
>
> In EurekaLog 5.x I have more potentially the threads exceptions
> handling, so EurekaLog 5 catches the FIBSQLMonitor bug (in the
> thread)!
I see. So the bug was probably always there, just not revealed.
> Have you just communicate to the FIBPlus authors about this bug and
> fix?
Yes, I just mentioned it on their newsgroup, but I haven't had a
response yet.
Thanks again!
--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.