|Perl: the Markov chain saw|
Win32, fork and XS globalsby syphilis (Canon)
|on Oct 02, 2011 at 04:49 UTC||Need Help??|
syphilis has asked for the
wisdom of the Perl Monks concerning the following question:
On linux that script fulfils my expectations and outputs:
But on Win32, I get:
The basic requirement is that the script forks; the child then alters the value of an XS global and exits; that global then still retains its original value.
What options are there that will bring Windows into line with Linux ?
Is there anything that can be done within the C code ?
Perhaps something regarding the way (when/how) the C component is loaded ?
It seems that system() produces a genuine fork, and (as desired) any setting of the global inside a system call is lost when the system call exits.
This is not so straightforward to demo with the Inline::C script, but in the real world scenario I'm dealing with an XS module - and using system instead of fork is one alternative.
But I'm keen to hear what, if any, other options exist - especially any that leave the fork() in place.
Interestingly enough, there's no such problem with *perl* globals. The following script works fine on both Win32 and linux:
It yields (as expected and desired):