Home > Archive > PERL Miscellaneous > April 2007 > passing objects to threads
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
passing objects to threads
|
|
| gaurava@lycos.com 2007-04-25, 8:01 am |
| 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
| |
| zentara 2007-04-25, 7:02 pm |
| On 24 Apr 2007 21:43:08 -0700, gaurava@lycos.com 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
|
|
|
|
|