Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Err, you are using alias there in a completely different sense than it is usually used in perl

From shared.xs:

* Shared scalar (my $s : shared): * * SV = PVMG(0x7ba238) at 0x7387a8 * FLAGS = (PADMY,GMG,SMG) * MAGIC = 0x824d88 * MG_TYPE = PERL_MAGIC_shared_scalar(n) * MG_PTR = 0x810358 <<<< pointer to the shared SV

No data is stored in the alias, it is just a pointer (with some attached magic), to the actual SV containing the data. That's a little fatter than a RV used for aliasing, but not much.

In the sense tye was talking about, which has nothing to do with where a thread starts running, threads emulate fork

A few extracts from the wikipedia page:

  • when a process forks, it creates a copy of itself.

    No new process is involved.

  • return value in the parent process is the PID of the newly-created child process.

    $$ returns the same value in all threads.

  • The fork operation creates a separate address space for the child.

    No separate address space is involved.

  • The child process has an exact copy of all the memory segments of the parent process,

    Not everything is copied. For example, lexicals are not cloned unless they are closed over by the thread sub.

    Data in shared scalars are not copied, another alias to it is created.

You might just as well say that forking emulates spawning a thread. After all, fork does spawn a thread. They obviously have similarities, but that's the nature of the beast. But they also have differences.

So no. Spawning an iThread is not exactly the same as spawning a thread in C or assembler. But then spawning a thread in Java, (or Python or Ruby, or LUA or Clean or Pure or O'Caml or OZ or ... ) is not the same as in C either.

Likewise, Perl's arrays are slower and heavier than C's. In the same way as you don't have direct access to shared memory; you don't have direct access to integers floats or strings in Perl. You go through a layer of Perl internals code to get to both. And you reap the benefits from doing so, from both.

Perl's built-in fork emulates *nix fork on Win32 (and OS/2,); threads->new() does not emulate fork. It just does some things that are similar.

Tye's statement has little technical merit, but a lot of political intent.


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.

In reply to Re^8: Utter FUD! by BrowserUk
in thread is ||= threadsafe? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2014-12-28 10:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (180 votes), past polls