hi all,

my question may seem silly somehow, but i'm just too lazy to RTFM:
as i understand that perf refs may not be shared between threads, does this mean, that calling DBI->connect_cached from within an thread won't work either?
to give you some help on what i exactly mean, here's the code:
sub event_handler { my $thread_sub = sub { my $event = SOD::EventCooker->new(shift); if (exists $p_ids{$res->{$_}->{'ev_p_id'}}) +{ # do something } else { my $dbh = DBI->connect_cached("DBI:mysql: +database=$appdata{DBBASE}", $appdata{DBUSER}, $appdata{DBPASS}, { RaiseError => 1, AutoCommit => 1 }) || die $dbh->errstr; $event->evaluate($dbh); } }; my @threads; my $dbh = DBI->connect("DBI:mysql:database=$appdata{DBBASE}", $appd +ata{DBUSER}, $appdata{DBPASS}, { RaiseError => 1, AutoCommit => 1 }) || die + $dbh->errstr; while (1) { sleep 1; last if $tflag; # $tflag is a shared global. my $thread_time : shared = time; my $res = $dbh->selectall_hashref("SELECT * FROM event WHERE ev_ +time<=$thread_time", 'ev_time'); $dbh->do("DELETE FROM event WHERE ev_time<=$thread_time"); map { push @threads, threads->new(\$thread_sub->($res->{$_})); } sort keys(%$res); map { $_->join; } @threads; @threads = (); } }
as you can see, the worker threads won't have a long lifetime. for perfomance reasons i'd like them to use cached connections to the database, but i'm afraid, that wo'nt work for the above reason.

am i right?

language is a virus from outer space.

In reply to DBI->connect_cached and threads? by thcsoft

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.