in reply to IPC::Shareable and Parallel::Forkmanager Question

I can't test my theory ( no IPC::Shareable on this machine ), but possibly the problem is that although you shlock your variable for the increment, you don't for when you test and restart it... what happens when you change you code to this? :

for(my $i = 0; $i < 100; $i++) { $pm->start and next; (tied $testvr)->shlock; if($testvr >= 5) { $testvr = 0; } $testvr++; print $testvr . "\n"; tied $testvr)->shunlock; $pm->finish; } $pm->wait_all_children;
Just a something something...

Replies are listed 'Best First'.
Re^2: IPC::Shareable and Parallel::Forkmanager Question
by anlamarama (Acolyte) on Nov 03, 2009 at 21:21 UTC

    I came here to correct my code but you have corrected it already :)

    Yes, that's the problem. Although I have said in my first post that locking does not help, I have done it wrong.

    What I have tried was this:

    for(my $i = 0; $i < 100; $i++) { $pm->start and next; (tied $testvr)->shlock; if($testvr >= 5) { $testvr = 0; } $testvr++; (tied $testvr)->shunlock; (tied $testvr)->shlock; print $testvr . "\n"; tied $testvr)->shunlock; $pm->finish; } $pm->wait_all_children;

    It does not work correctly. I was locking and unlocking twice. As it was a testing code, I did not care to write locking statement twice, I assumed that it is doing the same thing.

    Thanks