Pots::SharedAccessor - Perl ObjectThreads shared thread-safe accessors
package MyPackage; use base qw(Pots::SharedObject Pots::SharedAccessor); MyPackage->mk_shared_accessors(qw(field1 field2)); sub new { my $class = shift; my $self = $class->SUPER::new(); $self->field1(0); $self->field2(1); return $self } package main; my $o = MyPackage->new(); sub thread_proc { printf "field1 = %d, field2 = %d\n", $o->field1(), $o->field2(); sleep(5); printf "field1 = %d, field2 = %d\n", $o->field1(), $o->field2(); } my $th = threads->new("thread_proc"); $o->field1(5); $o->field2(42);
This pseudo-class allows you to use shared thread safe accessors in your shared objects.
This will create the accessor methods for field names in "@fields". These accessors methods can be called from other threads.
This module is HEAVILY based on Michael G Schwern's Class::Accessor. It has been revamped to include the shared behavior.
Class::Accessor
Remy Chibois <rchibois at free.fr>
Copyright (c) 2004 Remy Chibois. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Pots::Thread, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pots::Thread
CPAN shell
perl -MCPAN -e shell install Pots::Thread
For more information on module installation, please visit the detailed CPAN module installation guide.