Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The code and variable storage used by the modules will all be duplicated into every thread.

Not so, if you defer the loading of the modules and do it only within the thread or threads where it is required. That is what my post was demonstrating.

By requireing those modules required by each thread from within that thread, only that thread gets that code and data. If the thread then terminates, the memory used by those things it loaded is returned to the process' memory pool. Indeed, it is entirely possiible to have a single process that has HTTP::Daemon loaded in one thread; LWP in another; CGI in another; with none of them duplicated.

It is the fork-like "replicate everything currently loaded" behaviour that creates the problem. As I said elsewhere, if the choice of what was duplicated was left entirely to the programmer--life would be much simpler and iThreads would be considerably faster to start and lighter in use.

With forking, copy-on-write prevents this

If your OS supports fork-with-COW, then you're laughing--provided you do not need for the separate parts of your overall task to communicate. Under those circumstances, I too would use fork, and I do advocate that.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re^7: Isolating dynamically loaded modules with Thread::Isolate. by BrowserUk
in thread Isolating dynamically loaded modules with Thread::Isolate. by gmpassos

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found