Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Avoiding data copying in threads

by ganeshPerlStarter (Novice)
on Jul 01, 2014 at 08:59 UTC ( [id://1091811]=note: print w/replies, xml ) Need Help??


in reply to Re: Avoiding data copying in threads
in thread Avoiding data copying in threads

Hi x-lours, Thanks for this suggestion. However, isn't the use semaphore is more towards synchronization of threads (or processes)? I am using Thread::Queue to sync and communicate between threads. And, so synchronization and communication is not an issue. My main worry is about this behavior referred on this page: "It means that every time you start a thread all data structures are copied to the new thread. And when I say all, I mean all. This e.g. includes package stashes, global variables, lexicals in scope. Everything!" Thanks

Replies are listed 'Best First'.
Re^3: Avoiding data copying in threads
by Preceptor (Deacon) on Jul 01, 2014 at 09:37 UTC

    When you 'create' a thread - at the point at which you 'create' - the process state is copied.

    That can get quite expensive on memory overhead, yes. That is the way of things if you want to use Perl threads. You can mitigate it a little, by limiting memory footprint of your originator, and 'create' before you start filling memory with stuff you don't need in every thread.

    If you're on a system that supports it natively (e.g. most Unixes) then fork() may be an alternative - as most kernels implement copy-on-write for forked processes, meaning that they're very memory efficient. However you lose some of the conveniences that you'd get from e.g. threading.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1091811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found