NAME

Util::Shared - Allow users to have a single code base that may or may not use threads


SYNOPSIS

  use Util::Shared;
  my $hash = Util::Shared::create_hash();
  my $obj  = Util::Shared::create_hash('ClassName');
  my $new  = Util::Shared::clone($obj);
  print "My Thread Id: ", Util::Shared::tid(), "\n";


DESCRIPTION

Provides a set of static functions that can be used to write code that can be used in either single-threaded or multi-threaded applications.


FUNCTIONS

clone - Make a deep copy of an object. Depending upon the type of the object, it may result in recursive calls to clone in order to completely copy the object. If the object is blessed, the new object will also be blessed. In the case of references, the references are copied but the object to which it points is not. In multi-threaded mode, the new object is sharable.

create_array - This function will create a shared array and optionally bless it if a class name parameter is supplied. In single-threaded mode, the array will not be shared.

create_hash - This function will create a shared associative array and optionally bless it if a class name parameter is supplied. In single-threaded mode, the associative array will not be shared.

create_ref - This function will create a shared scalar and optionally bless it if a class name parameter is supplied. In single-threaded mode, the scalar will not be shared.

join - This function will call join() on all of the threads passed in. In single-threaded mode, this is a no-op.

threads - This function returns true if the version of Perl properly supports threads and threads have been enabled by setting the OPALORB_MULTI_THREADED environment variable to 1.

tid - This function returns the thread id for the calling thread. In single-threaded mode, this returns zero.