Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Passing objects between threads...any solutions? (shared objects)

by kimanaw (Beadle)
on Jun 10, 2005 at 03:32 UTC ( [id://465404]=note: print w/replies, xml ) Need Help??


in reply to Re: Passing objects between threads...any solutions? (shared objects)
in thread Passing objects between threads...any solutions ?

OK, lemme see if I follow the plot...

  1. You create a pool of "resource" objects whose members are all shared

  2. you pass the objects to the threads when they are created

  3. on creation, the thread dup's the resource object, thereby inheriting the shared members (albeit inside a new version of the object)

My only wrinkle is that I'm using a thread pool...but if I use a resource pool, I can instantiate the resource pool into each thread in the thread pool at startup, so I just need to add some scalar ID to each resource thread that can be used to direct a thread to whichever resource object to fiddle with.

Hmmm, intriguing...

I will definitely give it a shot. It may be a bit of a memory pig, but actually may also help limit the chances for memory leaks (kinda like building all Perl/Tk widgets at startup, and withdrawing til needed...kills memory leak bugs DEAD!)

PS. I do in fact have a dual CPU system (running Win2K); don't know when I'll get a chance to test this on it, (lots more code to implement/test before that), but I definitely owe you a barley pop...

And here's hoping Ponie solves this issue...

Many thanks...

  • Comment on Re^2: Passing objects between threads...any solutions? (shared objects)

Replies are listed 'Best First'.
Re^3: Passing objects between threads...any solutions? (shared objects)
by BrowserUk (Patriarch) on Jun 10, 2005 at 03:51 UTC
    but I definitely owe you a barley pop...

    If you could post (on your scratchpad) the results from running my test code on your dual processor and /msg me I'd be very happy.

    1. You create a pool of "resource" objects whose members are all shared

    2. ...

    3. ...

    That's not quite right, but I'm a too tired to correct it now. Check back later/tomorrow (before you start coding based on this) and I'll try to clarify.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      RE: dual CPU tests: will do, esp. since...

      RE: pool of resource objects

      I've managed to take your notion and run w/ it, and may even CPAN a module in the near future to do what I need, namely, create a ResourcePool object that acts as a pool/factory for objects of a specified type. Each thread gets the ResourcePool by default when the thread clones everything at create() time. Then the thread can either allocate() a fresh resource object from the ResourcePool, or use a scalar ID to get() an existing object. The thread either explicitly free()'s the object, or the resource's DESTROY() frees the object back to the pool when it goes out of scope (note the free() may only mean it is disassociated from the thread, but remains allocate()'d by other threads).

      Thanks for getting me headed in the right direction...

        You're welcome. I look forward to seeing how it pans out (as far as you are able to share it).


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-30 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found