passing objects to threads

G

gaurava

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
 
Z

zentara

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top