ext/threads/shared/t/av_refs.t Tests for arrays containing references
ext/threads/shared/t/av_simple.t Tests for basic shared array functionality.
ext/threads/shared/t/cond.t Test condition variables
+ext/threads/shared/t/disabled.t Test threads::shared when threads are disabled.
ext/threads/shared/t/hv_refs.t Test shared hashes containing references
ext/threads/shared/t/hv_simple.t Tests for basic shared hash functionality.
ext/threads/shared/t/no_share.t Tests for disabled share on variables.
require Exporter;
our @ISA = qw(Exporter);
-our @EXPORT = qw(share cond_wait cond_broadcast cond_signal _refcnt _id _thrcnt);
+our @EXPORT = qw(share cond_wait cond_broadcast cond_signal);
our $VERSION = '0.90';
if ($threads::threads) {
}
-sub cond_wait_disabled { return @_ };
-sub cond_signal_disabled { return @_};
-sub cond_broadcast_disabled { return @_};
-sub share_disabled { return @_}
+sub cond_wait_disabled (\[$@%]) { undef }
+sub cond_signal_disabled (\[$@%]) { undef }
+sub cond_broadcast_disabled (\[$@%]) { undef }
+sub share_disabled (\[$@%]) { return $_[0] }
$threads::shared::threads_shared = 1;
=head1 EXPORT
-C<share>, C<lock>, C<cond_wait>, C<cond_signal>, C<cond_broadcast>
+C<share>, C<cond_wait>, C<cond_signal>, C<cond_broadcast>
Note that if this module is imported when C<threads> has not yet been
loaded, then these functions all become no-ops. This makes it possible
C<share> takes a value and marks it as shared. You can share a scalar,
array, hash, scalar ref, array ref or hash ref. C<share> will return
-the shared rvalue.
+the shared rvalue but always as a reference.
C<share> will traverse up references exactly I<one> level.
C<share(\$a)> is equivalent to C<share($a)>, while C<share(\\$a)> is not.
--- /dev/null
+#!./perl -Tw
+
+# Tests of threads::shared's behavior when threads are disabled.
+
+BEGIN {
+ chdir 't';
+ @INC = '../lib';
+}
+
+# Can't use Test::More, it turns threads on.
+use Test;
+plan tests => 31;
+
+use threads::shared;
+
+# Make sure threads are really off.
+ok( !$INC{"threads.pm"} );
+
+# Check each faked function.
+foreach my $func (qw(share cond_wait cond_signal cond_broadcast)) {
+ ok( my $func_ref = __PACKAGE__->can($func) ? 1 : 0 );
+
+ eval qq{$func()};
+ ok( $@, qr/^Not enough arguments / );
+
+ my %hash = (foo => 42, bar => 23);
+ eval qq{$func(\%hash)};
+ ok( $@, '' );
+ ok( $hash{foo}, 42 );
+ ok( $hash{bar}, 23 );
+}
+
+# These all have no return value.
+foreach my $func (qw(cond_wait cond_signal cond_broadcast)) {
+ my @array = qw(1 2 3 4);
+ ok( eval qq{$func(\@array)}, undef );
+ ok( "@array", "1 2 3 4" );
+}
+
+# share() is supposed to return back it's argument as a ref.
+{
+ my @array = qw(1 2 3 4);
+ ok( share(@array), \@array );
+ ok( ref &share({}), 'HASH' );
+ ok( "@array", "1 2 3 4" );
+}
+
+# lock() should be a no-op. The return value is currently undefined.
+{
+ my @array = qw(1 2 3 4);
+ lock(@array);
+ ok( "@array", "1 2 3 4" );
+}
use strict;
BEGIN { print "1..13\n" };
use threads;
-use threads::shared qw(:DEFAULT _refcnt _id);
+use threads::shared;
ok(1,1,"loaded");
my $foo;
share($foo);
$$gg = "test";
ok(7, ${$foo{test}} eq "test", "Check reference");
my $gg2 = delete($foo{test});
-ok(8, _id($$gg) == _id($$gg2),
+ok(8, threads::shared::_id($$gg) == threads::shared::_id($$gg2),
sprintf("Check we get the same thing (%x vs %x)",
- _id($$gg),_id($$gg2)));
+ threads::shared::_id($$gg),threads::shared::_id($$gg2)));
ok(9, $$gg eq $$gg2, "And check the values are the same");
ok(10, keys %foo == 0, "And make sure we realy have deleted the values");
{