Subject Re: [IBO] Multithreaded application problem
Author Helen Borrie

At 02:16 PM 27/10/2004 +1300, you wrote:

>Hi All
>We are having strange problems with a multithreaded application using IBO
>components. This app runs fine on many (dozens) of machines however on
>Newer P4 machines running at 2.8Ghz (may be other higher speeds but thus far
>only 2.8 machines have been tested) and windows XP SP2 we are having
>The following code is in the execute part of a thread. The code crashes
>(Locks?) when trying to open the increment table. The exception either does
>not trigger or fails to save any message to the error file.
>I have traced the code by logging actions to a log. All components are
>created on the fly (No DM used here). TwsTable inherits from TIBOTable.
>The main VCL thread is running simultaneously. The application appears to
>lock, using 100% processor time. It never recovers.
>Am I doing something obviously wrong / dangerous? Any suggestions?
> if (ClientSesion = Nil) then begin
> ClientSesion := TIB_Session.Create(Nil);
> ClientSesion.UseCursor := False;
> //RM 22/06/2004 Firebird - Create Database for all table components
> IBODataBase := TIBODatabase.Create(ClientSesion);
> IBODataBase.Path := Owner.DataBasefullPath;
> IBODataBase.Password := WS_DB_PASSWORD;
> IBODataBase.Username := WS_DB_USERNAME;
> IBODataBase.Protocol := cpTCP_IP;

> // IBODataBase.PageSize := WS_DB_PAGESIZE;

> IBODataBase.IB_Session := ClientSesion;
> IBODataBase.SQLDialect := 3;
> IBODataBase.Connected := True;
> IncrementTable := TwsTable.Create(ClientSesion);
> IncrementTable.IB_Connection := IBODataBase;
> IncrementTable.TableName := 'Increment';
> try
> IncrementTable.OpenIfClosed;
> except
> on e: exception do begin
>RecordServerError('ROB TEST **', 'Processing Thread - 2d', 1, Now,
>e.message); //RM 27/10/2004 Testing
> end;
> end;
> end;
> while Terminated = False do begin
> ........

There are a few of things her that I'm dubious about.

One is your using the Connected property to connect to the database and
providing no exception checking on whether the connection was made. I'd
want to call Connect inside a try...except block and do a really thorough
cleanup if the thread fails to make the connection.

With that in mind, since you have no apparent "exit-and-cleanup" strategy
in the preceding code that is likely to cause the thread owner to terminate
the thread, that "while Terminated = False" loop looks pretty hairy. An
improperly handled exception inside this method (whatever it is) risks
throwing it into an infinite loop, from what I can tell here.