use strict; use warnings;
use threads;
use Thread::Semaphore;
use MCE::Shared;
use Time::HiRes 'time';
my $condvar = MCE::Shared->condvar;
my $sem = Thread::Semaphore->new;
# Start the shared server. Not necessary if Perl has IO::FDPass.
MCE::Shared->start;
sub test {
$condvar->wait;
for (1..10000) {
threads->yield;
$sem->down;
$sem->up;
}
}
threads->create('test') for 1..3;
$condvar->broadcast(0.5);
my $start = time;
$_->join for threads->list;
printf "duration: %0.03f secs\n", time - $start;
####
use strict; use warnings;
use threads;
use MCE::Mutex;
use MCE::Shared;
use Time::HiRes 'time';
my $condvar = MCE::Shared->condvar;
my $mutex = MCE::Mutex->new;
# Start the shared server. Not necessary if Perl has IO::FDPass.
MCE::Shared->start;
sub test {
$condvar->wait;
for (1..10000) {
threads->yield;
$mutex->lock;
$mutex->unlock;
}
}
threads->create('test') for 1..3;
$condvar->broadcast(0.5);
my $start = time;
$_->join for threads->list;
printf "duration: %0.03f secs\n", time - $start;
####
use strict; use warnings;
use threads;
use MCE::Mutex;
use MCE::Shared;
use Time::HiRes 'time';
my $condvar = MCE::Shared->condvar;
my $mutex = MCE::Mutex->new( impl => 'Flock' );
# Start the shared server. Not necessary if Perl has IO::FDPass.
MCE::Shared->start;
sub test {
$condvar->wait;
for (1..10000) {
threads->yield;
$mutex->lock;
$mutex->unlock;
}
}
threads->create('test') for 1..3;
$condvar->broadcast(0.5);
my $start = time;
$_->join for threads->list;
printf "duration: %0.03f secs\n", time - $start;
####
Thread::Semaphore 0.386 secs
MCE::Mutex::Channel 0.162 secs
MCE::Mutex::Flock 0.144 secs
####
Thread::Semaphore 0.293 secs
MCE::Mutex::Channel 0.499 secs
MCE::Mutex::Flock 0.498 secs
####
Thread::Semaphore 41.897 secs
MCE::Mutex::Channel 0.980 secs
MCE::Mutex::Flock 0.702 secs
####
Thread::Semaphore 35.521 secs
MCE::Mutex::Channel 2.994 secs
MCE::Mutex::Flock 3.322 secs