Hi, I'm trying to make a threaded app with database connections. I was having low performance (20% cpu usage) because the site sending the data is limited in speed. So I tried launching another process of my program and I got to do twice as much,as expected. So I tried to make my app multithreaded. To feed the threads, I need to query a database (READ), and the threads themselves do database access too (Write). So I went with something like this:
$dbh=... $sth->execute() $sth->bind_columns(...) t1= new Thread \&processor; t2= new Thread \&processor; t1->join(); t2->join(); #ends here# sub hitMe { # :locked? $sth->fetch(); return (columns...); } sub processor { my $dbconn.... my $dbh... while(@data=hitme()) { process stuff; $dbh->something(); } }
But it complains that the connection is already being used by thread N (program's main thread) and that db handlers aren't shared. So how can I feed my threads with data from the db in a synchronized manner? Thanks

In reply to databases and multithreading by hjf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.