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

Re^3: Sharing globs

by renodino (Curate)
on Nov 02, 2007 at 17:21 UTC ( #648697=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Sharing globs
in thread Sharing globs

Nice piece of detective work!

I'm troubled by this statement:

And once a shared glob has been stored in a hash value, it looses some or all of its magic.

Presumably, the assignment to the 'httpd_daemon' element in the shared *HASH is going thru the sharedsv_elem_mg_STORE() method, which should end up in sharedsv_scalar_store(). Have you tried sprinkling the latter with printf's to see what path it takes ? I'd assume its handled as an RV, but maybe something else is going on...( I have vague memories of a recent p5p posting regarding a threads::shared patch to address chained magic, but can't seem to find anything in the changelog...but make sure you're using the latest version)

FWIW I'm personally still not comfortable with just dup()'ing; I've experienced too many weird behaviors with both block and (esp.) stream I/O when things get dup()'ed. I'm also concerned about the possibility of piling up dup's if an app has a master thread repeatedly/arbitrarily passing file handles around to worker threads. But if the sharing magic can be fixed, then that problem can presumably be fixed by stealing the clone code for handles, and then (a) checking if the file already has context in the recving thread and (b) cloning the state into the recving thread at that point if it doesn't.

(BTW: maybe this dialogue needs to be moved to the ithreads maillist ?)


Perl Contrarian & SQL fanboy


Comment on Re^3: Sharing globs
Re^4: Sharing globs
by BrowserUk (Pope) on Nov 02, 2007 at 18:06 UTC

    I made my modifications to shared.xs 1.12, which was the latest version when I started. I noticed jdhedden released 1.14 recently which I have installed but haven't got around to catching up with yet. I need to add all my changes and tracing to it before I can continue my investigations.

    Here's the output from a really simple test I ran (that won't work without the mods I've made). Sorry for the mess it will look in the browser, but if you C&P it to an editor with a reasonably wide screen it should sort itself out.

    What it shows is the output from Devel::Peek::Dump() of the same glob returned from Symbol::gensym():

    The first (leftmost) is what it looks like as returned.

    The second is how it looks after it has been shared (after mods). You can see that it is still the same animal. It has retained the glob magic, and gains the shared scalar magic. At this point, the shared copy works as the original in every way I've tried. If I use a glob returned by IO::Socket::INET, all the methods work on the copy as normal. In the originating thread and in any other thread that uses it.

    The third is what you see after you assign the original as a value to a shared hash.

    The fourth if you assign the copy.

    As you can see, all the glob and shared scalar magic has been replaced by shared element magic and all the good stuff done by share() seems to have been blown away.

    Maybe I'm misinterpreting this output, this is somewhat of a work in progress that has recently been interupted by other things. What I do know is that after you assign a globref to a hash (or array element), it no longer acts as a globref, which is probably why it was disabled in the first place.

    But I am convinced that it is a limitation of the magic handling in share.xs, rather than a fundamental limitation of perl's magic handling.


    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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2014-09-17 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (92 votes), past polls