Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Shared objects and refcount/weaken bug?

by BrowserUk (Patriarch)
on Mar 01, 2012 at 10:01 UTC ( [id://957144]=note: print w/replies, xml ) Need Help??


in reply to Shared objects and refcount/weaken bug?

Part of the problem is that you are messing with the refcounts of the proxy object, not the actual shared object which you do not have access to.

Shared data is implemented such that the actual storage used lives in an interpreter space that is inaccessible from Perl.

The variables that you declare 'shared; in your code, are proxies -- place-holders -- for use by your threads to gain access to the actual data via attached magic.

When one thread dies, any proxies it holds to a share variable are destroyed, but the actual shared data may not be, if some other thread still holds a reference to it.

That is, the refcounts on the inaccessible shared data have to count all references from all threads. When the reference count on a proxy in one thread drops to zero, that proxy is destroyed, and refcount of the actual data is decremented, but may not reach zero at the same time if some other continuing thread has a reference to it.

The upshot is, that messing with the refcounts of shared things is probably a bad idea and almost certainly isn't achieving whatever you set out to achieve by doing it.

Originally, and until relatively recently, it wasn't possible to share blessed things. I think for very good reasons.

Unfortunately, it doesn't look like the implementation that added the ability to shared blessed objects was properly thought through.

(Personally, I advise against sharing objects between threads -- it is (IMO) entirely the wrong approach to the problem; where required, threading should occur within objects -- but if you do use shared objects, messing with their refcounts is just asking for trouble.)

One thing that does look like a real bug -- rather than just an odd corner you should never go into -- is the weirdness of a second call to Devel::Refcount preventing the destruction of the object. That looks very iffy to me.


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?

  • Comment on Re: Shared objects and refcount/weaken bug?

Replies are listed 'Best First'.
Re^2: Shared objects and refcount/weaken bug?
by menth0l (Monk) on Mar 01, 2012 at 10:13 UTC
    Actually i used refcount only to check if weaken works as expected (which is not). I don't use it in my code.
      Actually i used refcount only to check if weaken works as expected

      I appreciate that; but the affect it has is still questionable.

      However, using weaken is still "messing with the refcounts of shared things", and as such is inadvisable.


      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?

        Yeah, i've learned it the hard way :/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-20 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found