Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
The stupid question is the question not asked
 
PerlMonks  

Re^2: Sharing Package variables across threads

by metaperl (Curate)
on Sep 01, 2011 at 08:15 UTC ( #923587=note: print w/ replies, xml ) Need Help??


in reply to Re: Sharing Package variables across threads
in thread Sharing Package variables across threads

Yes, but since the threads are in the same process, when a new thread is made, are copies made of package variables also if they arent marked as shared? I'm sorry for these "dumb" questions, but the idea of two threads in the same process is a bit confusing to me.



The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"


Comment on Re^2: Sharing Package variables across threads
Re^3: Sharing Package variables across threads
by Anonymous Monk on Sep 01, 2011 at 09:50 UTC

    Yes, but since the threads are in the same process, when a new thread is made, are copies made of package variables also if they arent marked as shared? I'm sorry for these "dumb" questions, but the idea of two threads in the same process is a bit confusing to me.

    perlthrtut#Shared And Unshared Data
    by default, no data is shared.
    When a new Perl thread is created, all the data associated with the current thread is copied to the new thread, and is subsequently private to that new thread!
    http://en.wikipedia.org/wiki/Thread_%28computer_science%29
    In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. It generally results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources. In particular, the threads of a process share the latter's instructions (its code) and its context (the values that its variables reference at any given moment). To give an analogy, multiple threads in a process are like multiple cooks reading off the same cook book and following its instructions, not necessarily from the same page.
    perlthrtut#What Is A Thread Anyway?
    A thread is a flow of control through a program with a single execution point.

    Sounds an awful lot like a process, doesn't it? Well, it should. Threads are one of the pieces of a process. Every process has at least one thread and, up until now, every process running Perl had only one thread. With 5.8, though, you can create extra threads.

Re^3: Sharing Package variables across threads
by ikegami (Pope) on Sep 01, 2011 at 18:22 UTC
    Come on, bud, try it! You even have the code already, you just need to remove the call to share.
Re^3: Sharing Package variables across threads
by ikegami (Pope) on Sep 01, 2011 at 18:24 UTC

    the idea of two threads in the same process is a bit confusing to me.

    Don't you mean "the idea of threads is a bit confusing to me"?

    Threads are always in the same process. One never deals with threads in other processes.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-04-19 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls