NAME

Coro::LocalScalar::XS - Different scalar values in coroutines

ABOUT

This is optimized XS version of Coro::LocalScalar. It's almost two times faster and has simplier api - only one function.

SYNOPSIS

use Coro;
use Coro::EV;


my $scalar;

use Coro::LocalScalar::XS;
localize($scalar); # $scalar is now different in all coros. Current value of $scalar is deleted.

# $hash{element} = undef; # hash element MUST exist if you want to localize it correctly
# localize($hash{element}); 
# localizing arrays or hashes unsupported, use refs

# or
# use Coro::LocalScalar::XS qw//; # don't export localize
# Coro::LocalScalar::XS->localize($scalar);

async {
		$scalar = "thread 1";
		print "1 - $scalar\n";
		cede;
		print "3 - $scalar\n";
		cede;
		print "5 - $scalar\n";
		
};

async {
		$scalar = "thread 2";
		print "2 - $scalar\n";
		cede;
		print "4 - $scalar\n";
		cede;
		print "6 - $scalar\n";
};

EV::loop;



1 - thread 1
2 - thread 2
3 - thread 1
4 - thread 2
5 - thread 1
6 - thread 2

BENCHMARK

 t/benchmark.pl

						Rate Coro::LocalScalar Coro::LocalScalar::XS Coro::Localize
Coro::LocalScalar     10000/s                --                  -45%           -52%
Coro::LocalScalar::XS 18282/s               83%                    --           -12%
Coro::Localize        20661/s              107%                   13%             --

Coro::Localize is little bit faster, but Coro::LocalScalar::XS allows localizing hash elements