NAME

Thread::SharedTreeSet - Shared set of recursive hashes/arrays using serialization

VERSION

0.01

SYNOPSIS

use threads;
use Thread::SharedTree;
use Data::Dumper;

my $h = Thread::SharedTree->new();

threads->create( 'a', $h->{'id'} );
threads->create( 'b', $h->{'id'} );

wait_for_threads();

sub a {
    my $hid = shift;
    my $h = Thread::SharedTree->new( id => $hid );
    $h->set( 'a', { test => 'blah' } );
    $h->ilock('a');
    sleep(4);
    $h->iunlock('a');
}

sub b {
    my $hid = shift;
    my $h = Thread::SharedTree->new( id => $hid );
    sleep(1);
    $h->ilock('a');
    my $data = $h->get('a');
    $h->iunlock('a');
    print Dumper( $data );
}

sub wait_for_threads {
    while( 1 ) {
        my @joinable = threads->list(0);#joinable
        my @running = threads->list(1);#running
        
        for my $thr ( @joinable ) { $thr->join(); }
        last if( !@running );
        sleep(1);
    }
}

DESCRIPTION

Thread::SharedTreeSet makes it possible to share a set of recursive hashes/arrays between threads. Each shared tree set created has a unique scalar identifier that can be used to fetch that same shared tree set from another thread.

LICENSE

Copyright (C) 2013 David Helkowski

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.  You may also can
redistribute it and/or modify it under the terms of the Perl
Artistic License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.