5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
15 print("1..0 # Skip: Needs Perl 5.10.0 or later\n");
20 use ExtUtils::testlib;
24 print("1..28\n"); ### Number of tests that will be run ###
42 # You have to do it this way or VMS will get confused.
44 print("ok $id - $name\n");
46 print("not ok $id - $name\n");
47 printf("# Failed test at line %d\n", (caller)[2]);
55 ### Start of Testing ###
62 bless(&threads::shared::share({}), shift);
67 my ($self, $cookie) = @_;
69 return $jar[-1]; # Results in destruction of proxy object
87 my $self = bless(&threads::shared::share({}), shift);
88 $self->{'type'} = shift;
94 delete(shift->{'type'});
98 my $C1 = 'chocolate chip';
99 my $C2 = 'oatmeal raisin';
100 my $C3 = 'vanilla wafer';
102 my $cookie = Cookie->new($C1);
103 ok($cookie->{'type'} eq $C1, 'Have cookie');
105 my $jar = Jar->new();
106 $jar->store($cookie);
108 ok($cookie->{'type'} eq $C1, 'Still have cookie');
109 ok($jar->peek()->{'type'} eq $C1, 'Still have cookie');
110 ok($cookie->{'type'} eq $C1, 'Still have cookie');
112 threads->create(sub {
113 ok($cookie->{'type'} eq $C1, 'Have cookie in thread');
114 ok($jar->peek()->{'type'} eq $C1, 'Still have cookie in thread');
115 ok($cookie->{'type'} eq $C1, 'Still have cookie in thread');
117 $jar->store(Cookie->new($C2));
118 ok($jar->peek()->{'type'} eq $C2, 'Added cookie in thread');
121 ok($cookie->{'type'} eq $C1, 'Still have original cookie after thread');
122 ok($jar->peek()->{'type'} eq $C2, 'Still have added cookie after thread');
124 $cookie = $jar->fetch();
125 ok($cookie->{'type'} eq $C2, 'Fetched cookie from jar');
126 ok($jar->peek()->{'type'} eq $C1, 'Cookie still in jar');
128 $cookie = $jar->fetch();
129 ok($cookie->{'type'} eq $C1, 'Fetched cookie from jar');
133 $cookie = $jar->store(Cookie->new($C3));
134 ok($jar->peek()->{'type'} eq $C3, 'New cookie in jar');
135 ok($cookie->{'type'} eq $C3, 'Have cookie');
137 threads->create(sub {
138 ok($cookie->{'type'} eq $C3, 'Have cookie in thread');
139 $cookie = Cookie->new($C1);
140 ok($cookie->{'type'} eq $C1, 'Change cookie in thread');
141 ok($jar->peek()->{'type'} eq $C3, 'Still have cookie in jar');
144 ok($cookie->{'type'} eq $C1, 'Have changed cookie after thread');
145 ok($jar->peek()->{'type'} eq $C3, 'Still have cookie in jar');
147 ok($jar->peek()->{'type'} eq $C3, 'Still have cookie in jar');
148 $cookie = $jar->fetch();
149 ok($cookie->{'type'} eq $C3, 'Fetched cookie from jar');
154 threads::shared::share($ID);
158 # Anonymous scalar with an internal ID
159 my $obj = \do{ my $scalar = $ID++; };
160 threads::shared::share($obj); # Make it shared
161 return (bless($obj, 'Foo')); # Make it an object
167 ok($$obj == 1, "Main: Object ID $$obj");
169 threads->create( sub {
170 ok($$obj == 1, "Thread: Object ID $$obj");
173 ok($$obj == 10, "Thread: Changed object ID $$obj");
176 ok($$obj == 2, "Thread: New object ID $$obj");
179 ok($$obj == 2, "Main: New object ID $$obj # TODO - should be 2");