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;
}