summaryrefslogtreecommitdiff
path: root/t/lib/thread.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lib/thread.t')
-rw-r--r--t/lib/thread.t54
1 files changed, 54 insertions, 0 deletions
diff --git a/t/lib/thread.t b/t/lib/thread.t
new file mode 100644
index 0000000000..798adc12be
--- /dev/null
+++ b/t/lib/thread.t
@@ -0,0 +1,54 @@
+#!perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require Config; import Config;
+ if ($Config{'ccflags'} !~ /-DUSE_THREADS\b/) {
+ print "1..0\n";
+ exit 0;
+ }
+}
+$| = 1;
+print "1..9\n";
+use Thread;
+print "ok 1\n";
+
+sub content
+{
+ print shift;
+ return shift;
+}
+
+# create a thread passing args and immedaietly wait for it.
+my $t = new Thread \&content,("ok 2\n","ok 3\n");
+print $t->join;
+
+# check that lock works ...
+{lock $foo;
+ $t = new Thread sub { lock $foo; print "ok 5\n" };
+ print "ok 4\n";
+}
+$t->join;
+
+sub islocked
+{
+ use attrs 'locked';
+ my $val = shift;
+ my $ret;
+ if (@_)
+ {
+ $ret = new Thread \&islocked,shift;
+ sleep 2;
+ }
+ print $val;
+}
+
+$t = islocked("ok 6\n","ok 7\n");
+join $t;
+
+# test that sleep lets other thread run
+$t = new Thread \&islocked,"ok 8\n";
+sleep 2;
+print "ok 9";
+join $t;