Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Shared objects and refcount/weaken bug?

by sundialsvc4 (Abbot)
on Mar 01, 2012 at 14:31 UTC ( [id://957232]=note: print w/replies, xml ) Need Help??


in reply to Shared objects and refcount/weaken bug?

Echoing this sentiment, if you have many threads hitting the same shared objects and trying to do work in parallel to one another and in complete disregard for one another, you will find yourself battling stochastic probability distributions when you ought to be debugging.

I think that sharing objects among threads is good for about one thing:   to avoid copying things in memory.   And that advantage, quite frankly, is dubious at best, given the amount of instability that it can cause.   (When that thing goes into production, you need to know that it will be rock-solid for weeks at a time.)

I prefer therefore to simplify the architecture; to reduce the number of possibilities, to an amount that is limited, and that can be simulated in advance of the system’s actual construction.   I prefer to have one thread that is the producer (and the destructor) of all shared data, and the worker threads are consumers who withdraw the data from a queue, and who place them back onto another queue for eventual destruction, filing, or recycling as the case may be.   (And when you do that, of course, the “shared data” part of it probably goes away and I say, “good riddance.”)   The whole scenario is now greatly simplified:   one actor both creates the objects and disposes of them; each actor is working on just one thing at a time albeit in parallel; each thing is being worked on, at any particular instant, by only one actor at a time even though many things may be being worked on at a time.   That is a design that can run continuously forever.   If the work being performed by each worker is substantial and if the number of those workers can be throttled, backlogs and shortages are unlikely to develop (as simulations will predict).   And is it (perhaps except in the bleeding-edge situations that I know BrowserUK does routinely work with ...) “fast enough?”   (IMLE) Yes, away from that edge, surely.   Our world is filled with just such designs.

Replies are listed 'Best First'.
Re^2: Shared objects and refcount/weaken bug?
by BrowserUk (Patriarch) on Mar 01, 2012 at 15:20 UTC
    I think that sharing objects among threads is good for about one thing: to avoid copying things in memory.

    Do me a favour and post code, 10 lines should do it, that demonstrates this for me. Please?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re^2: Shared objects and refcount/weaken bug?
by BrowserUk (Patriarch) on Mar 01, 2012 at 22:21 UTC

    Come on, let me save your precious time and get you started...

    #! perl -slw use strict; use threads; use threads::shared; ## just six more short lines needed here

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-03-28 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found