Mutex::Util - Utility functions for Mutex
This document describes Mutex::Util version 1.011
# Mutex::Util functions are beneficial inside a class. package Foo::Bar; use strict; use warnings; our $VERSION = '0.002'; use Mutex::Util; my $has_threads = $INC{'threads.pm'} ? 1 : 0; my $tid = $has_threads ? threads->tid : 0; sub CLONE { $tid = threads->tid if $has_threads; } sub new { my ($class, %obj) = @_; $obj{init_pid} = $has_threads ? "$$.$tid" : $$; ($^O eq 'MSWin32') ? Mutex::Util::sock_pair(\%obj, qw(_r_sock _w_sock)) : Mutex::Util::pipe_pair(\%obj, qw(_r_sock _w_sock)); ... return bless \%obj, $class; } sub DESTROY { my ($pid, $obj) = ($has_threads ? "$$.$tid" : $$, @_); if ($obj->{init_pid} eq $pid) { ($^O eq 'MSWin32') ? Mutex::Util::destroy_socks($obj, qw(_w_sock _r_sock)) : Mutex::Util::destroy_pipes($obj, qw(_w_sock _r_sock)); } return; } 1;
Useful functions for managing pipe and socket handles stored in a hashref.
Destroy pipes in the hash for given key names.
Mutex::Util::destroy_pipes($hashref, qw(_w_sock _r_sock));
Destroy sockets in the hash for given key names.
Mutex::Util::destroy_socks($hashref, qw(_w_sock _r_sock));
Creates a pair of connected pipes and stores the handles into the hash with given key names representing the two read-write handles. Optionally, pipes may be constructed into an array stored inside the hash.
Mutex::Util::pipe_pair($hashref, qw(_r_sock _w_sock)); $hashref->{_r_sock}; $hashref->{_w_sock}; Mutex::Util::pipe_pair($hashref, qw(_r_sock _w_sock), $_) for 0..3; $hashref->{_r_sock}[0]; $hashref->{_w_sock}[0];
Creates an unnamed pair of sockets and stores the handles into the hash with given key names representing the two read-write handles. Optionally, sockets may be constructed into an array stored inside the hash.
Mutex::Util::sock_pair($hashref, qw(_r_sock _w_sock)); $hashref->{_r_sock}; $hashref->{_w_sock}; Mutex::Util::sock_pair($hashref, qw(_r_sock _w_sock), $_) for 0..3; $hashref->{_r_sock}[0]; $hashref->{_w_sock}[0];
Mario E. Roy, <marioeroy AT gmail DOT com>
To install Mutex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mutex
CPAN shell
perl -MCPAN -e shell install Mutex
For more information on module installation, please visit the detailed CPAN module installation guide.