Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Perl isn't thread safe. You'll need to do one of the following:

  • Use some sort of mutex to prevent simultaneous access to the Perl interpreter, making a "critical section" that only one thread can use at a time. I believe someone has already built this so you might be able to find it.
  • Create (a pool of) separate Perl interpreters for each thread that needs to call a Perl subroutines. This won't work for you if the subroutines need to act on shared data. Note that you can use the same Perl interpreter in different threads so long as the Perl interpreter is not built with threading support and only one thread uses that interpreter at a time.
  • Try embedding a Perl interpreter built with one of the several experimental methods for supporting multiple thread per interpreter and access the interpreter as required by that method. This will cause the interpreter to use mutexes to make critical sections around smaller chunks of code. But none of these work 100% reliably so you'll have to deal with that.
There might be some other methods, but the above should give you a feel for what is required.

Please contact me at

Sorry, you'll have to check back here.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Accessing one perl sub by multiple threads.. by tye
in thread Accessing one perl sub by multiple threads.. by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [LanX]: White House indicates it could find funds to train 1 million teachers ...
    [LanX]: wait
    [LanX]: White House indicates it could find funds to train and arm 1 million teachers!
    LanX relieved...
    [Discipulus]: too much guns in schools? throw more gun at schools! professors in arms

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2018-02-23 11:32 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (301 votes). Check out past polls.