Actually no, I did not. I thought what was in the preview was what I had typed and it looked (well) like what I typed. My bad. Doh. Hey ya'll using p and code now.

Right now I can't even make sense of the use of what I think is just about as simple an example I can start with. The Hash keys value changes between subsequent prints and that has me looping on wtf.

and OMG, using p and code produced entirely different preview results!!!

What I am trying to do is share a Hash (actually may Hash's) of Perl managed SQLite (module) DB's by using threads and threads::shared such that a Hash of 'many' open DB handles gets used by 'many' threads (concurrently executing but restricting concurrently executing on the same DB handle). Around that I have other Hash associated with the Hash of DB handles that help me ensure single thread usage of individual handles so that I can process either a single (for right now) query of many DB (handles) concurrently OR (more generically and more directly to the real intent) many threads serving many query requests concurrently while ensuring that each DB handle is only being used by one thread at a time (using a spin-lock structure).

I might have 10's, 100's or even 1000's of DB handles open concurrently and 'many' threads.

What this does is remove the 'cost' of opening/closing individual DB's for a query. The actual open/close are done by the threads, if a DB is targeted for query but is not in the open DB handle Hash it gets opened (for all to see) while another thread is maintaining the maximum-open-handles using a LRU structure so I can (example) configure to 1000 open DB handles (max) and threads accumulate their list of target DB files, open the file if not already in the DB handle hash, query pre-DB-handle only-one-at-a-time (enforced/signaled by a shared spin-lock Hash), and the maximum open is monitored and enforced by a LRU monitor, spin/repeat.

Right now this is essentially all happening in development code but now as I try to turn the non-shared Hash into shared I am getting 'compile' errors. So because the Hash are non-shared each thread subroutine is of course copying stuff when instantiated but then runs locally with duplicated rather than shared handles -- not what I want (it runs but not the next level of refinement).

[root@itx2 ~]# cat x8.pl use DBI; use threads; use threads::shared; my $dsn :shared; my %hash :shared; my $Sdatabase :shared; $Sdatabase = '/opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old';# $ARGV +[0]; $dsn = "DBI:SQLite:dbname=$Sdatabase"; $hash{"$Sdatabase"} = shared_clone(DBI->connect($dsn, '', '', { PrintE +rror => 1, RaiseError => 1, AutoCommit => 0, ReadOnly => 1 })); print '$hash{"$Sdatabase"} -> ' . $Sdatabase . ' -> ' . $hash{"$Sdatab +ase"} . "\n"; print '$hash{"$Sdatabase"} -> ' . $Sdatabase . ' -> ' . $hash{"$Sdatab +ase"} . "\n"; print '$hash{"$Sdatabase"} -> ' . $Sdatabase . ' -> ' . $hash{"$Sdatab +ase"} . "\n"; exit; [root@itx2 ~]# perl x8.pl $hash{"$Sdatabase"} -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old + -> DBI::db=HASH(0x562a9cb92f50) $hash{"$Sdatabase"} -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old + -> DBI::db=HASH(0x562a9c858f60) $hash{"$Sdatabase"} -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old + -> DBI::db=HASH(0x562a9c8593c8) [root@itx2 ~]#

Right now because I can't even get a single Hash key to have a stable value between repeated prints all the other stuff, possible or not, will just have to wait realizing my goal of a shared Hash of SQLite DB handles....


In reply to Re^6: threads::shared referencing confusion by Anonymous Monk
in thread threads::shared referencing confusion by Anonymous Monk

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.