NAME
forks::BerkeleyDB::shared - high-performance drop-in replacement for threads::shared
SYNOPSYS
use forks::BerkeleyDB;
use forks::BerkeleyDB::shared;
my $variable : shared;
my @array : shared;
my %hash : shared;
share( $variable );
share( @array );
share( %hash );
lock( $variable );
cond_wait( $variable );
cond_wait( $variable, $lock_variable );
cond_timedwait( $variable, abs time );
cond_timedwait( $variable, abs time, $lock_variable );
cond_signal( $variable );
cond_broadcast( $variable );
DESCRIPTION
forks::BerkeleyDB::shared is a drop-in replacement for threads::shared, written as an extension of forks::shared. The goal of this module improve upon the core performance of forks::shared at a level reasonably comparable to native ithreads (threads::shared).
USAGE
See forks::shared for common usage information.
Location of database files
This module will use $ENV{TMPDIR} (unless taint is on) or /tmp for all back-end database and other support files. For the most part, BerkeleyDB will use shared memory for as much frequently accesed data as possible, so you probably won't notice drive-based performance hits. For optimal performance, use a partition with a physical drive dedicate for tempory space usage.
NOTES
Forks 0.19 or later is required to support transparent blessing across threads. This feature will be silently disabled if this requirement is not met.
Currently optimizes SCALAR, ARRAY, and HASH shared variables. HANDLE type is supported using the default method implemented by forks::shared.
Shared variable access and modification are NOT guaranteed to be handled as atomic events. This deviates from undocumented forks behavior, where all these events are atomic, but it correctly models the expected behavior of threads. Thus, don't forget to lock() your shared variable before using them concurrently in multiple threads; otherwise, results may not be what you expect.
When share is used on arrays, hashes, array refs or hash refs, any data they contain will be lost. This correctly models the expected behavior of threads, but not (currently) of forks.
CAVIATS
It appears that BerkeleyDB libdb 4.4.x environments are not fully thread-safe with BerkeleyDB CDB mode on some platforms. Thus, it is highly recommended you use libdb 4.3.x and earlier, or 4.5.x and later.
TODO
Monitor number of connected shared variables per thread and dynamically disconnect uncommonly used vars based on last usage and/or frequency of usage (to meet BDB environment lock limits).
Implement shared variable locks, signals, and waiting with BerkeleyDB.
AUTHOR
Eric Rybski <rybskej@yahoo.com>.
COPYRIGHT
Copyright (c) 2006-2007 Eric Rybski <rybskej@yahoo.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.