[yunqa.de] Re: TDISQLite3Database.UnRegisterStatement thread-safe?

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Sun, 30 Aug 2009 09:02:14 +0200

At 23:29 29.08.2009, Nick Bradbury wrote:

>Several customers have sent me error logs from my application which show 
>EListError exceptions in TDISQLite3Database.UnRegisterStatement.  
> 
>My app always writes to the database in the main thread, but there are several 
>read operations that occur in background threads which rely on prepared 
>statements created on-the-fly in those threads.
> 
>Looking at DISQLite3Database.pas, I see that the list of prepared statements 
>(FStatements) is a TList rather than a thread-safe list (TThreadList).  Could 
>this be the cause of these EListError exceptions?

Thanks for the catch. Yes, changing

  FStatements: TList;

into 

  FStatements: TThreadList;

in DISQLite3Database.pas is a quick fix which will improve your situation, but 
it still leaves FStatements.Count non-threadsave.

It is safer IMO to wrap all access to FStatements using a dedicated mutex 
within TDISQLite3Database.

I will send the code after I have completed a few more tests.

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: