NAME

Thread::Serialize - serialize data-structures between threads

SYNOPSIS

use Thread::Serialize;    # export freeze() and thaw()

use Thread::Serialize (); # must call fully qualified subs

my $frozen = freeze( any data structure );
any data structure = thaw( $frozen );

DESCRIPTION

                 *** A note of CAUTION ***

This module only functions on Perl versions 5.8.0 and later.
And then only when threads are enabled with -Dusethreads.  It
is of no use with any version of Perl before 5.8.0 or without
threads enabled.

                 *************************

The Thread::Serialize module is a library for centralizing the routines used to serialize data-structures between threads. Because of this central location, other modules such as Thread::Conveyor, Thread::Pool or Thread::Tie can benefit from the same optimilizations that may take place here in the future.

SUBROUTINES

There are only two subroutines.

freeze

my $frozen = freeze( $scalar );

my $frozen = freeze( @array );

The "freeze" subroutine takes all the parameters passed to it, freezes them and returns a frozen representation of what was given. The parameters can be scalar values or references to arrays or hashes. Use the thaw subroutine to obtain the original data-structure back.

thaw

my $scalar = thaw( $frozen );

my @array = thaw( $frozen );

The "thaw" subroutine returns the data-structure that was frozen with a call to freeze. If called in a scalar context, only the first element of the data-structure that was passed, will be returned. Otherwise the entire data-structure will be returned.

It is up to the developer to make sure that single argument calls to freeze are always matched by scalar context calls to thaw.

OPTIMIZATIONS

To reduce memory and CPU usage, this module uses AutoLoader. This causes subroutines only to be compiled in a thread when they are actually needed at the expense of more CPU when they need to be compiled. Simple benchmarks however revealed that the overhead of the compiling single routines is not much more (and sometimes a lot less) than the overhead of cloning a Perl interpreter with a lot of subroutines pre-loaded.

CAVEATS

As an extra optimization, the signature value for frozen Storable values is pre-computed. This may break however with future versions. If you should experience breakage, then you can cause the signature value to be re-computed at compile time by specifying the environment variable NOT_ICED, either before you start Perl or by adding

BEGIN { $ENV{NOT_ICED} = 1 }

before the use Thread::Serialize. Or, if you feel sure about yourself, you can assign the signature yourself thus:

$Thread::Serialize::iced = unpack( 'l',Storable::freeze( [] ) );

before actually executing any code. However, this will break the optimization of not needing the freeze() code in every thread.

AUTHOR

Elizabeth Mattijsen, <liz@dijkmat.nl>.

Please report bugs to <perlbugs@dijkmat.nl>.

COPYRIGHT

Copyright (c) 2002 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Thread::Conveyor, Thread::Pool, Thread::Tie.