Hi Folks, I have recently discoverred a strange behaviour of forking and shared memory under windows. Below is the code in concern:
#!C:/Perl/bin/perl -w
use strict;
use Win32::MMF::Shareable;
if( fork )
{
my $ns = tie( my %share, 'Win32::MMF::Shareable', 'share' ) || die;
sleep 1;
$share{parent} = 1;
# select undef, undef, undef, 2.0; <----- dummy line
}
else
{
my $ns = tie( my %share, 'Win32::MMF::Shareable', 'share' ) || die;
$share{child} = 1;
}
When I remove the dummy line, which is commented anyway, the code crashes Perl with "Free to wrong pool <address> not <address> during global destruction" error. When I leave the dummy line, the code executes without problem, on my machine anyway.
I am out of ideas as why this is happenning. Can anyone see what might be causing this strange behaviour? I have researched on the web, and I found the following description:
usually under ithreads when the interpreter context is wrong and a memory from the wrong pool is allocated.
What does this mean? Does it have anything to do with the behavious I am getting?
Thanks for your suggestions.
Update:
I put a '!' (negation) in front of fork, and it seems not to crash any more. It seems that the parent must finish first?
if( ! fork )
{
my $ns = tie( my %share, 'Win32::MMF::Shareable', 'share' ) || die;
sleep 1;
$share{parent} = 1;
}
else
{
my $ns = tie( my %share, 'Win32::MMF::Shareable', 'share' ) || die;
$share{child} = 1;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.