BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deadlock when both IBX and BDE objects used in different thr

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (InterBase Express)
View previous topic :: View next topic  
Author Message
Max
Guest





PostPosted: Wed Oct 19, 2005 11:08 pm    Post subject: Deadlock when both IBX and BDE objects used in different thr Reply with quote



I have the big LEGACY application in BCB6, which uses many BDE
components (TDatabase, TQuery, etc). One of the modules has to
modify several tables in the interbase database, when data in
another table were modified. Application has a thread A
(TThread), which encapsulates the required database modification
code (using BDE objects, see above). The main thread has IBEvents
and TIBDatabase objects. TIBDatabase object connects to database
in the constructor of the main form, and IBEvents fires its
OnEventAlert event when the After Update trigger in the database
table POST_EVENT. This OnEventAlert event sets the Windows event,
which is waited for (WaitForMultipleObjects) in the thread A.
Upon return from WaitForMultipleObjects, thread A resets this
Windows event, and performs the needed operations on the
database (all BDE objects were declared and defined in the
TThread::Execute method, also new session was open there), and
waits again. This thread waits for several different Windows
events, and it acts differently depending on the event received
(this is the reason to have this thread). This awkward construct
(use of both BDE and IBX) is because this application has been
written long ago when IBEvents was located in BDE group and used
TDatabase. Replacing BDE elements for IBX is difficult, because
application is big, and it uses InfoPower Controls, which require BDE data access components.

However, this construct does not work. Either thread A hangs
while connecting to the database (if thread A connects the
TDatabase after connecting the TIBDatabase in the main thread)
or OnEventAlert event is never fired (if TDatabase and
IBDatabase connect to the database in the opposite order). It
looks IBX and BDE objects interfere when used in different
threads. I moved all database operations, which have been
located previously in the thread A, into the Synchronize
function of the thread A (now all TDatabase, TQuery, ets. are
declared and defined in the main thread, and two connections to
database are still used). Everything works great. However, this
is very awkward, and I do not understand why BDE objects work in
different threads (when separate sessions are used), but BDE and
IBX do not.

The question is how could I get rid of the Syncronize method,
and move BDE objects into thread A? Does the BDE version of
IBEvents exist?

Thanks for reply...
Max Fish
Back to top
Wayne Niddery [TeamB]
Guest





PostPosted: Thu Oct 20, 2005 3:34 am    Post subject: Re: Deadlock when both IBX and BDE objects used in different Reply with quote



Max wrote:
Quote:
I have the big LEGACY application in BCB6, which uses many BDE
components (TDatabase, TQuery, etc).
[snip]
Replacing BDE elements for IBX is difficult, because
application is big, and it uses InfoPower Controls, which require BDE
data access components.

The Infopower controls for this late a version of BCB should not require
BDE, they should work with any TDataset descendant.

Quote:
However, this construct does not work. Either thread A hangs
while connecting to the database (if thread A connects the
TDatabase after connecting the TIBDatabase in the main thread)
or OnEventAlert event is never fired (if TDatabase and
IBDatabase connect to the database in the opposite order). It
looks IBX and BDE objects interfere when used in different
threads.

There should be no interaction at all between the BDE and IBX components.
You have done right as far as making sure the thread has its own BDE
objects, however I think you'll find the problem is that the BDE simply
cannot handle working in threads very well - I've seen and experienced
problems with this myself in the past. While it may be some work to do, the
very best thing you can do is switch the thread to use IBX components and
get rid of the BDE components there. It will be worth the effort.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"Some see private enterprise as a predatory target to be shot, others
as a cow to be milked, but few are those who see it as a sturdy horse
pulling the wagon." - Winston Churchill
Back to top
Steve
Guest





PostPosted: Thu Oct 20, 2005 10:00 pm    Post subject: Re: Deadlock when both IBX and BDE objects used in different Reply with quote



Max wrote:
Quote:

table POST_EVENT. This OnEventAlert event sets the Windows event,
which is waited for (WaitForMultipleObjects) in the thread A.
Upon return from WaitForMultipleObjects, thread A resets this
Windows event, and performs the needed operations on the

You might try MsgWaitForMultipleObjectsEx instead of
WaitForMultipleObjects. This allows the message queue to continue to
process. In my TThreaded application switching resolved a couple of my
deadlocks. I assume that both the BDE and IBX access Forms and such,
thus need the message processing to continue.
Back to top
Jeff Overcash (TeamB)
Guest





PostPosted: Thu Oct 20, 2005 10:03 pm    Post subject: Re: Deadlock when both IBX and BDE objects used in different Reply with quote

"Wayne Niddery [TeamB]" wrote:
Quote:


There should be no interaction at all between the BDE and IBX components.
You have done right as far as making sure the thread has its own BDE
objects, however I think you'll find the problem is that the BDE simply
cannot handle working in threads very well - I've seen and experienced
problems with this myself in the past. While it may be some work to do, the
very best thing you can do is switch the thread to use IBX components and
get rid of the BDE components there. It will be worth the effort.


Also don't forget that events don't actually fire until you commit the
transaction that you raise them in.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Your friends will know you better in the first minute you meet than your
acquaintances will know you in a thousand years. (R Bach)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (InterBase Express) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.