Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code:102) in /var/www/iplanru/data/www/intesco.ru/d59ed/index.php(1) : eval()'d code(2) : eval()'d code on line 4
package threads;
use 5.008;
use strict;
use warnings;
our $VERSION = '1.72';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
# Verify this Perl supports threads
require Config;
if (! $Config::Config{useithreads}) {
die("This Perl not built to support threads\n");
}
# Complain if 'threads' is loaded after 'threads::shared'
if ($threads::shared::threads_shared) {
warn <<'_MSG_';
Warning, threads::shared has already been loaded. To
enable shared variables, 'use threads' must be called
before threads::shared or any module that uses it.
_MSG_
}
# Declare that we have been loaded
$threads::threads = 1;
# Load the XS code
require XSLoader;
XSLoader::load('threads', $XS_VERSION);
### Export ###
sub import
{
my $class = shift; # Not used
# Exported subroutines
my @EXPORT = qw(async);
# Handle args
while (my $sym = shift) {
if ($sym =~ /^(?:stack|exit)/i) {
if (defined(my $arg = shift)) {
if ($sym =~ /^stack/i) {
threads->set_stack_size($arg);
} else {
$threads::thread_exit_only = $arg =~ /^thread/i;
}
} else {
require Carp;
Carp::croak("threads: Missing argument for option: $sym");
}
} elsif ($sym =~ /^str/i) {
import overload ('""' => \&tid);
} elsif ($sym =~ /^(?::all|yield)$/) {
push(@EXPORT, qw(yield));
} else {
require Carp;
Carp::croak("threads: Unknown import option: $sym");
}
}
# Export subroutine names
my $caller = caller();
foreach my $sym (@EXPORT) {
no strict 'refs';
*{$caller.'::'.$sym} = \&{$sym};
}
# Set stack size via environment variable
if (exists($ENV{'PERL5_ITHREADS_STACK_SIZE'})) {
threads->set_stack_size($ENV{'PERL5_ITHREADS_STACK_SIZE'});
}
}
### Methods, etc. ###
# Exit from a thread (only)
sub exit
{
my ($class, $status) = @_;
if (! defined($status)) {
$status = 0;
}
# Class method only
if (ref($class)) {
require Carp;
Carp::croak('Usage: threads->exit(status)');
}
$class->set_thread_exit_only(1);
CORE::exit($status);
}
# 'Constant' args for threads->list()
sub threads::all { }
sub threads::running { 1 }
sub threads::joinable { 0 }
# 'new' is an alias for 'create'
*new = \&create;
# 'async' is a function alias for the 'threads->create()' method
sub async (&;@)
{
unshift(@_, 'threads');
# Use "goto" trick to avoid pad problems from 5.8.1 (fixed in 5.8.2)
goto &create;
}
# Thread object equality checking
use overload (
'==' => \&equal,
'!=' => sub { ! equal(@_) },
'fallback' => 1
);
1;
__END__
=head1 NAME
threads - Perl interpreter-based threads
=head1 VERSION
This document describes threads version 1.72
=head1 SYNOPSIS
use threads ('yield',
'stack_size' => 64*4096,
'exit' => 'threads_only',
'stringify');
sub start_thread {
my @args = @_;
print('Thread started: ', join(' ', @args), "\n");
}
my $thr = threads->create('start_thread', 'argument');
$thr->join();
threads->create(sub { print("I am a thread\n"); })->join();
my $thr2 = async { foreach (@files) { ... } };
$thr2->join();
if (my $err = $thr2->error()) {
warn("Thread error: $err\n");
}
# Invoke thread in list context (implicit) so it can return a list
my ($thr) = threads->create(sub { return (qw/a b c/); });
# or specify list context explicitly
my $thr = threads->create({'context' => 'list'},
sub { return (qw/a b c/); });
my @results = $thr->join();
$thr->detach();
# Get a thread's object
$thr = threads->self();
$thr = threads->object($tid);
# Get a thread's ID
$tid = threads->tid();
$tid = $thr->tid();
$tid = "$thr";
# Give other threads a chance to run
threads->yield();
yield();
# Lists of non-detached threads
my @threads = threads->list();
my $thread_count = threads->list();
my @running = threads->list(threads::running);
my @joinable = threads->list(threads::joinable);
# Test thread objects
if ($thr1 == $thr2) {
...
}
# Manage thread stack size
$stack_size = threads->get_stack_size();
$old_size = threads->set_stack_size(32*4096);
# Create a thread with a specific context and stack size
my $thr = threads->create({ 'context' => 'list',
'stack_size' => 32*4096,
'exit' => 'thread_only' },
\&foo);
# Get thread's context
my $wantarray = $thr->wantarray();
# Check thread's state
if ($thr->is_running()) {
sleep(1);
}
if ($thr->is_joinable()) {
$thr->join();
}
# Send a signal to a thread
$thr->kill('SIGUSR1');
# Exit a thread
threads->exit();
=head1 DESCRIPTION
Perl 5.6 introduced something called interpreter threads. Interpreter threads
are different from I<5005threads> (the thread model of Perl 5.005) by creating
a new Perl interpreter per thread, and not sharing any data or state between
threads by default.
Prior to Perl 5.8, this has only been available to people embedding Perl, and
for emulating fork() on Windows.
The I API is loosely based on the old Thread.pm API. It is very
important to note that variables are not shared between threads, all variables
are by default thread local. To use shared variables one must also use
L:
use threads;
use threads::shared;
It is also important to note that you must enable threads by doing C