On Fri, 30 Jan 2015, Fabrício Srdic wrote:

Hello,

The DB access framework of the fpc is not thread safe.

So, how can i build a multithreaded application that requires access to 
database?

Create 1 connection per thread. Do not share connections (and datasets connected to it) over threads.

If each one of my threads use its own set of DB access components, that is, 
don´t share any instance of db access components, this can
be a secure workaround?

Yes, if they use a connection per thread.

The main problem is that the 'Database' and 'Transaction' properties of TDBDataset and descendents (TBufDataset and TSQLQuery) are not thread safe: The TDatabase class maintains a list of connected datasets. The management of this list is not thread-safe, it needs to be changed to a TThreadList. This is on my todo list, but is part of a bigger rework.

Note that the underlying DB client library also may not be thread safe.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to