passing objects to threads

Discussion in 'Perl Misc' started by gaurava@lycos.com, Apr 25, 2007.

  1. Guest

    Hi,
    I am trying to create a new thread within my script and use a global
    object reference within the thread. The global object is initialized
    before it is passed to the thread. However the thread doesn't receive
    an initialized copy. It gets a copy of the reference. I am doing:

    use Thread;

    Should I use threads and threads::shared? How do I share object
    references?

    Thanks,
    Gaurav
     
    , Apr 25, 2007
    #1
    1. Advertising

  2. zentara Guest

    On 24 Apr 2007 21:43:08 -0700, wrote:

    >Hi,
    > I am trying to create a new thread within my script and use a global
    >object reference within the thread. The global object is initialized
    >before it is passed to the thread. However the thread doesn't receive
    >an initialized copy. It gets a copy of the reference. I am doing:
    >
    >use Thread;
    >
    >Should I use threads and threads::shared? How do I share object
    >references?
    >
    >Thanks,
    >Gaurav


    You are treading on quicksand, normally you don't share
    objects across threads. Most objects should be consider
    NOT-threadsafe, unless otherwise proven.

    You are best to contain objects
    within a single thread, and share data through shared scalars.
    Think about a strategy where you have objects contained
    in a single thread and you reuse them, by clearing them out
    and feeding them new data through shared variables.


    But read this if you really need it:
    http://perlmonks.org?node_id=465380


    zentara


    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
     
    zentara, Apr 25, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yoda
    Replies:
    2
    Views:
    445
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  2. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    411
    William Ahern
    Aug 27, 2004
  3. 7stud
    Replies:
    11
    Views:
    700
    Dennis Lee Bieber
    Mar 20, 2007
  4. ghoetker
    Replies:
    1
    Views:
    378
  5. Samuel
    Replies:
    1
    Views:
    79
    Samuel
    May 20, 2007
Loading...

Share This Page