<br><br><div class="gmail_quote">2011/10/3 Ludo Brands <span dir="ltr"><<a href="mailto:ludo.brands@free.fr">ludo.brands@free.fr</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<u></u>
<div><div class="im">
<blockquote style="padding-left: 5px; margin-left: 5px; border-left: 2px solid rgb(0, 0, 255); margin-right: 0px;">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="padding-left: 1ex; margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);">
<div>
<div align="left" lang="fr"><span><font color="#0000ff" face="Arial" size="2">The
minimum requirement for multithreaded db access is to use a separate db
connection for every thread and transaction isolation.</font></span></div>
<div>
<blockquote style="padding-left: 5px; margin-left: 5px; border-left: 2px solid rgb(0, 0, 255); margin-right: 0px;">
<div dir="ltr" align="left" lang="fr"><span></span><font color="#0000ff" face="Arial" size="2"></font><br>I am not sure if the database library code
is faulty or looking up the values in a thread is the
problem<br><span><font color="#0000ff" face="Arial" size="2"> </font></span></div></blockquote></div>
<div align="left" lang="fr"><span><font color="#0000ff" face="Arial" size="2">Some
database client libraries have problems with multithreading or have
threadsafe versions (fe. libmysql.dll is not threadsafe in the standard
version). </font></span></div>
<div>
<blockquote style="padding-left: 5px; margin-left: 5px; border-left: 2px solid rgb(0, 0, 255); margin-right: 0px;">
<div dir="ltr" align="left" lang="fr"><span></span><font color="#0000ff" face="Arial" size="2"></font><br>The database lookup code is in a data
module running in the main thread. Do I have to use a critical section in
data module containing the threads to the database lookup?<br><span><font color="#0000ff" face="Arial" size="2"> </font></span></div></blockquote></div>
<div align="left" lang="fr"><span><font color="#0000ff" face="Arial" size="2">No. That
is trying to solve the problem in the wrong place.</font></span></div>
<div align="left" lang="fr"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div><font color="#888888">
<div align="left" lang="fr"><span><font color="#0000ff" face="Arial" size="2">Ludo</font></span></div></font></div><br></blockquote><font color="#0000ff" face="Arial" size="2"></font>
<div><br><br>If I put a TCP component such as an Indy http component on that
data module, and get all the lookups to be done over the http socket, is that
likely to fix the problem, rather than calling the database lookup code in the
data module directly from the threads?<br> <span><font color="#0000ff" face="Arial" size="2"> </font></span></div></div></blockquote>
</div><div><span><font color="#0000ff" face="Arial" size="2">You
mean you have a 2nd path to your database over http? As long as you
don't use the same database connection (session) from the different threads and
are sure there are no transaction isolation issues you can use whatever
communication protocol you like. Seems complicating things
though.</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2">Why
don't you write a data lookup class in your data module that uses it's own
Txxxconnection,TSQLTransaction and TSqlQuery and have each thread use its own
instance? Destroy after use or, when frequent data updates are needed, give it a
DisConnect method so that the number of sessions remains reasonable. If you have
a lot of threads and the number of simultanuous database sessions is an issue,
then write one lookup procedure using a criticial section but, again, using
its own database connection: enter criticial section, connect to database,
run sql, retrieve data, disconnect, exit critical section. </font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div><font color="#888888">
<div><span><font color="#0000ff" face="Arial" size="2">Ludo</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div></font></div></blockquote><div><br><br>I am now using a separate TConnection for the threaded code and now all the values are found if the database lookup code executes, but it seems that the database lookup is not called all the time, and this may be due to some of the threads not executing properly.<br>
<br>I will make some more tests to see where the other problems might be<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>
<font color="#888888">
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div></font></div>
<br>--<br>
_______________________________________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Frank Church<br><br>=======================<br><a href="http://devblog.brahmancreations.com">http://devblog.brahmancreations.com</a><br>