This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
threads::shared TODO test for outstanding bug
authorJerry D. Hedden <jdhedden@cpan.org>
Wed, 30 Jan 2008 09:15:25 +0000 (04:15 -0500)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 31 Jan 2008 17:08:22 +0000 (17:08 +0000)
From: "Jerry D. Hedden" <jdhedden@cpan.org>
Message-ID: <1ff86f510801300615t1f9e8c68u5ff8caaeffb1a835@mail.gmail.com>

p4raw-id: //depot/perl@33154

ext/threads/shared/t/object.t

index d244a31..5c5a55e 100644 (file)
@@ -21,7 +21,7 @@ use ExtUtils::testlib;
 
 BEGIN {
     $| = 1;
-    print("1..23\n");   ### Number of tests that will be run ###
+    print("1..28\n");   ### Number of tests that will be run ###
 };
 
 use threads;
@@ -148,4 +148,34 @@ ok($jar->peek()->{'type'} eq $C3, 'Still have cookie in jar');
 $cookie = $jar->fetch();
 ok($cookie->{'type'}      eq $C3, 'Fetched cookie from jar');
 
+{ package Foo;
+
+    my $ID = 1;
+    threads::shared::share($ID);
+
+    sub new
+    {
+        # Anonymous scalar with an internal ID
+        my $obj = \do{ my $scalar = $ID++; };
+        threads::shared::share($obj);   # Make it shared
+        return (bless($obj, 'Foo'));    # Make it an object
+    }
+}
+
+my $obj :shared;
+$obj = Foo->new();
+ok($$obj == 1, "Main: Object ID $$obj");
+
+threads->create( sub {
+        ok($$obj == 1, "Thread: Object ID $$obj");
+
+        $$obj = 10;
+        ok($$obj == 10, "Thread: Changed object ID $$obj");
+
+        $obj = Foo->new();
+        ok($$obj == 2, "Thread: New object ID $$obj");
+    } )->join();
+
+ok($$obj == 2, "Main: New object ID $$obj  # TODO - should be 2");
+
 # EOF