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

Re^2: Win32, fork and XS globals

by ikegami (Pope)
on Oct 02, 2011 at 05:38 UTC ( #929102=note: print w/ replies, xml ) Need Help??


in reply to Re: Win32, fork and XS globals
in thread Win32, fork and XS globals

That perlmod link is not terribly useful. For instructions on creating per-interpreter variables, see "Safely Storing Static Data in XS" in perlxs. It even includes an example.

The mechanism allows each interpreter in a process to have their own copies of variables. This is useful not only when threads are involved, but in all instances when a process has multiple Perl interpreters (e.g. mod_perl?).


Comment on Re^2: Win32, fork and XS globals
Re^3: Win32, fork and XS globals
by BrowserUk (Pope) on Oct 02, 2011 at 06:09 UTC
    It even includes an example.

    Personally, I found that example almost completely useless. An example of "Safely Storing Static Data" that doesn't appear to declare any static data is pretty worthless.

    And having half a dozen macros all named SOM_BG_MNGLSS_ABBREV only differentiated by a single even more meaningless, wimpy prefix character a or d or p or maybe an almost invisible _ prefix or suffix, is stupid, bordering on the criminal.

    Which is why I didn't mention it.

    Of course, if you'd offered this information as a reply to the OP rather throwing it at me, you wouldn't have got this response.


    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.

      Of course it's not allocated statically. It can't be both static and per-interpreter.

      "_" represents the even less visible ",", so complaints of visibility are silly.

      "d", "a" and "p" stand for "declare", "argument" and "parameter", and are used throughout the API just like "SV". The pattern is documented. There's a point as uses grows where short and convenient becomes more convenient than crystal clarity, and the use of "d", "a" and "p" are justified or nearly justified by this (like $_ is).

        Why not address your replies to the person asking the question, cos I already know this stuff.


        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.
Re^3: Win32, fork and XS globals
by syphilis (Canon) on Oct 02, 2011 at 08:15 UTC
    Be buggered ... this actually seems to work:
    use warnings; use Inline C => Config => NAME => 'expt', BOOT => " { MY_CXT_INIT; MY_CXT.count = 5; } ", BUILD_NOISY => 1, ; use Inline C => <<'EOC'; #define MY_CXT_KEY "expt::_guts" XS_VERSION typedef struct { int count; } my_cxt_t; START_MY_CXT void set_x(int z) { dMY_CXT; MY_CXT.count = z; } void get_x(char * id) { dMY_CXT; printf("%s %d\n", id, MY_CXT.count); } void CLONE(SV * x, ...) { MY_CXT_CLONE; } EOC get_x('1st call:'); if($pid = fork()) { waitpid($pid,0); } else { set_x(10); get_x('2nd call:'); exit(0); } get_x('3rd call:');
    It outputs:
    1st call: 5 2nd call: 10 3rd call: 5
    Must investigate further.

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-08-22 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls