summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANIFEST1
-rw-r--r--t/class/threads.t47
2 files changed, 48 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 63d7ba0f4c..c1c2bfb618 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -5648,6 +5648,7 @@ t/class/field.t See if class field declarations work
t/class/inherit.t See if class inheritance works
t/class/method.t See if class method declarations work
t/class/phasers.t See if class phaser blocks work
+t/class/threads.t See if classes work across multiple threads
t/cmd/elsif.t See if else-if works
t/cmd/for.t See if for loops work
t/cmd/mod.t See if statement modifiers work
diff --git a/t/class/threads.t b/t/class/threads.t
new file mode 100644
index 0000000000..4bd9fa444d
--- /dev/null
+++ b/t/class/threads.t
@@ -0,0 +1,47 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ require './test.pl';
+ set_up_inc('../lib');
+ require Config;
+
+ skip_all_without_config('useithreads');
+ skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
+}
+
+use v5.36;
+use feature 'class';
+no warnings 'experimental::class';
+
+use threads;
+
+class Test1 {
+ field $x :param;
+ method x { return $x }
+}
+
+{
+ my $ret = threads->create(sub {
+ pass("Created dummy thread");
+ return 1;
+ })->join;
+ next_test(); # account for pass() inside thread
+ is($ret, 1, "Returned from dummy thread");
+}
+
+{
+ my $obj = Test1->new(x => 10);
+ threads->create(sub {
+ is($obj->x, 10, '$obj->x inside thread created before');
+ })->join;
+ next_test(); # account for is() inside thread
+}
+
+threads->create(sub {
+ my $obj = Test1->new(x => 20);
+ is($obj->x, 20, '$obj->x created inside thread');
+})->join;
+next_test(); # account for is() inside thread
+
+done_testing;