stevieb9 / ipc-shareable

Share Perl variables across processes and scripts
GNU General Public License v2.0
3 stars 2 forks source link

Figure out why NEXTKEY's each() breaks if an external process updates a hash #40

Open stevieb9 opened 10 months ago

stevieb9 commented 10 months ago

This may fix the having to use Dumper

stevieb9 commented 10 months ago

We need to reproduce the issue so we can test it and fix it.

stevieb9 commented 10 months ago

To test this, we could remove the Dumper statement in global_register() and see if we can reproduce the problem there.

See if a full hash reassignment does the same thing Dumper does

https://stackoverflow.com/questions/3010712/how-do-perl-firstkey-and-nextkey-work

This actually may be a race condition between a STORE and FETCH

Tie::Hash doc: http://ww2.cs.lamar.edu/doc/perl-doc/pod/perltie.html

Check whether NEXTKEY is even used in a hash iteration, or if just FIRSTKEY is

stevieb9 commented 10 months ago

Should we change things like this?

sub FIRSTKEY {
    my $self = shift;

    #build iterator     
    $self->{_list} = [ sort keys %{$self->{_hash}} ];    

    return $self->NEXTKEY;
}

sub NEXTKEY {
    my $self = shift;

    return shift @{$self->{_list}};
}
stevieb9 commented 10 months ago

See #38