1898184e3Ssthenuse strict; 2898184e3Ssthenuse warnings; 3898184e3Ssthen 4898184e3SsthenBEGIN { 5898184e3Ssthen use Config; 6898184e3Ssthen if (! $Config{'useithreads'}) { 7898184e3Ssthen print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8898184e3Ssthen exit(0); 9898184e3Ssthen } 10898184e3Ssthen if ($] < 5.010) { 11898184e3Ssthen print("1..0 # SKIP Needs Perl 5.10.0 or later\n"); 12898184e3Ssthen exit(0); 13898184e3Ssthen } 14898184e3Ssthen} 15898184e3Ssthen 16898184e3Ssthenuse ExtUtils::testlib; 17898184e3Ssthen 18898184e3SsthenBEGIN { 19898184e3Ssthen $| = 1; 20*9f11ffb7Safresh1 print("1..133\n"); ### Number of tests that will be run ### 21898184e3Ssthen}; 22898184e3Ssthen 23898184e3Ssthenuse threads; 24898184e3Ssthenuse threads::shared; 25898184e3Ssthen 26898184e3Ssthenmy $TEST; 27898184e3SsthenBEGIN { 28898184e3Ssthen share($TEST); 29898184e3Ssthen $TEST = 1; 30898184e3Ssthen} 31898184e3Ssthen 32898184e3Ssthensub ok { 33898184e3Ssthen my ($ok, $name) = @_; 34898184e3Ssthen 35898184e3Ssthen lock($TEST); 36898184e3Ssthen my $id = $TEST++; 37898184e3Ssthen 38898184e3Ssthen # You have to do it this way or VMS will get confused. 39898184e3Ssthen if ($ok) { 40898184e3Ssthen print("ok $id - $name\n"); 41898184e3Ssthen } else { 42898184e3Ssthen print("not ok $id - $name\n"); 43898184e3Ssthen printf("# Failed test at line %d\n", (caller)[2]); 44898184e3Ssthen } 45898184e3Ssthen 46898184e3Ssthen return ($ok); 47898184e3Ssthen} 48898184e3Ssthen 49898184e3Ssthenok(1, 'Loaded'); 50898184e3Ssthen 51898184e3Ssthen### Start of Testing ### 52898184e3Ssthen 53898184e3Ssthenmy $ID :shared = -1; 54898184e3Ssthenmy (@created, @destroyed); 55898184e3Ssthen 56898184e3Ssthen{ package HashObj; 57898184e3Ssthen sub new { 58898184e3Ssthen my $class = shift; 59898184e3Ssthen my $self = &threads::shared::share({}); 60898184e3Ssthen $$self{'ID'} = ++$ID; 61898184e3Ssthen $created[$ID] = 1; 62898184e3Ssthen return bless($self, $class); 63898184e3Ssthen } 64898184e3Ssthen 65898184e3Ssthen sub DESTROY { 66898184e3Ssthen my $self = shift; 67898184e3Ssthen $destroyed[$$self{'ID'}] = 1; 68898184e3Ssthen } 69898184e3Ssthen} 70898184e3Ssthen 71898184e3Ssthen{ package AryObj; 72898184e3Ssthen sub new { 73898184e3Ssthen my $class = shift; 74898184e3Ssthen my $self = &threads::shared::share([]); 75898184e3Ssthen $$self[0] = ++$ID; 76898184e3Ssthen $created[$ID] = 1; 77898184e3Ssthen return bless($self, $class); 78898184e3Ssthen } 79898184e3Ssthen 80898184e3Ssthen sub DESTROY { 81898184e3Ssthen my $self = shift; 82898184e3Ssthen $destroyed[$$self[0]] = 1; 83898184e3Ssthen } 84898184e3Ssthen} 85898184e3Ssthen 86898184e3Ssthen{ package SclrObj; 87898184e3Ssthen sub new { 88898184e3Ssthen my $class = shift; 89898184e3Ssthen my $self = \do{ my $scalar = ++$ID; }; 90898184e3Ssthen $created[$ID] = 1; 91898184e3Ssthen threads::shared::share($self); 92898184e3Ssthen return bless($self, $class); 93898184e3Ssthen } 94898184e3Ssthen 95898184e3Ssthen sub DESTROY { 96898184e3Ssthen my $self = shift; 97898184e3Ssthen $destroyed[$$self] = 1; 98898184e3Ssthen } 99898184e3Ssthen} 100898184e3Ssthen 101898184e3Ssthen# Testing with normal array 102898184e3Ssthenmy @normal_ary; 103898184e3Ssthen 104898184e3Ssthen# Testing with hash object 105898184e3Ssthen$normal_ary[0] = HashObj->new(); 106898184e3Ssthenok($created[$ID], 'Created hash object in normal array'); 107898184e3Ssthendelete($normal_ary[0]); 108898184e3Ssthenok($destroyed[$ID], 'Deleted hash object in normal array'); 109898184e3Ssthen 110898184e3Ssthen$normal_ary[0] = HashObj->new(); 111898184e3Ssthenok($created[$ID], 'Created hash object in normal array'); 112898184e3Ssthen$normal_ary[0] = undef; 113898184e3Ssthenok($destroyed[$ID], 'Undef hash object in normal array'); 114898184e3Ssthen 115898184e3Ssthen$normal_ary[0] = HashObj->new(); 116898184e3Ssthenok($created[$ID], 'Created hash object in normal array'); 117898184e3Ssthen$normal_ary[0] = HashObj->new(); 118898184e3Ssthenok($created[$ID], 'Created hash object in normal array'); 119898184e3Ssthenok($destroyed[$ID-1], 'Replaced hash object in normal array'); 120898184e3Ssthen@normal_ary = (); 121898184e3Ssthenok($destroyed[$ID], 'Hash object removed from cleared normal array'); 122898184e3Ssthen 123898184e3Ssthen$normal_ary[0] = HashObj->new(); 124898184e3Ssthenok($created[$ID], 'Created hash object in normal array'); 125898184e3Ssthenundef(@normal_ary); 126898184e3Ssthenok($destroyed[$ID], 'Hash object removed from undef normal array'); 127898184e3Ssthen 128898184e3Ssthen# Testing with array object 129898184e3Ssthen$normal_ary[0] = AryObj->new(); 130898184e3Ssthenok($created[$ID], 'Created array object in normal array'); 131898184e3Ssthendelete($normal_ary[0]); 132898184e3Ssthenok($destroyed[$ID], 'Deleted array object in normal array'); 133898184e3Ssthen 134898184e3Ssthen$normal_ary[0] = AryObj->new(); 135898184e3Ssthenok($created[$ID], 'Created array object in normal array'); 136898184e3Ssthen$normal_ary[0] = undef; 137898184e3Ssthenok($destroyed[$ID], 'Undef array object in normal array'); 138898184e3Ssthen 139898184e3Ssthen$normal_ary[0] = AryObj->new(); 140898184e3Ssthenok($created[$ID], 'Created array object in normal array'); 141898184e3Ssthen$normal_ary[0] = AryObj->new(); 142898184e3Ssthenok($created[$ID], 'Created array object in normal array'); 143898184e3Ssthenok($destroyed[$ID-1], 'Replaced array object in normal array'); 144898184e3Ssthen@normal_ary = (); 145898184e3Ssthenok($destroyed[$ID], 'Array object removed from cleared normal array'); 146898184e3Ssthen 147898184e3Ssthen$normal_ary[0] = AryObj->new(); 148898184e3Ssthenok($created[$ID], 'Created array object in normal array'); 149898184e3Ssthenundef(@normal_ary); 150898184e3Ssthenok($destroyed[$ID], 'Array object removed from undef normal array'); 151898184e3Ssthen 152898184e3Ssthen# Testing with scalar object 153898184e3Ssthen$normal_ary[0] = SclrObj->new(); 154898184e3Ssthenok($created[$ID], 'Created scalar object in normal array'); 155898184e3Ssthendelete($normal_ary[0]); 156898184e3Ssthenok($destroyed[$ID], 'Deleted scalar object in normal array'); 157898184e3Ssthen 158898184e3Ssthen$normal_ary[0] = SclrObj->new(); 159898184e3Ssthenok($created[$ID], 'Created scalar object in normal array'); 160898184e3Ssthen$normal_ary[0] = undef; 161898184e3Ssthenok($destroyed[$ID], 'Undef scalar object in normal array'); 162898184e3Ssthen 163898184e3Ssthen$normal_ary[0] = SclrObj->new(); 164898184e3Ssthenok($created[$ID], 'Created scalar object in normal array'); 165898184e3Ssthen$normal_ary[0] = SclrObj->new(); 166898184e3Ssthenok($created[$ID], 'Created scalar object in normal array'); 167898184e3Ssthenok($destroyed[$ID-1], 'Replaced scalar object in normal array'); 168898184e3Ssthen@normal_ary = (); 169898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from cleared normal array'); 170898184e3Ssthen 171898184e3Ssthen$normal_ary[0] = SclrObj->new(); 172898184e3Ssthenok($created[$ID], 'Created scalar object in normal array'); 173898184e3Ssthenundef(@normal_ary); 174898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from undef normal array'); 175898184e3Ssthen 176898184e3Ssthen# Testing with normal hash 177898184e3Ssthenmy %normal_hash; 178898184e3Ssthen 179898184e3Ssthen# Testing with hash object 180898184e3Ssthen$normal_hash{'obj'} = HashObj->new(); 181898184e3Ssthenok($created[$ID], 'Created hash object in normal hash'); 182898184e3Ssthendelete($normal_hash{'obj'}); 183898184e3Ssthenok($destroyed[$ID], 'Deleted hash object in normal hash'); 184898184e3Ssthen 185898184e3Ssthen$normal_hash{'obj'} = HashObj->new(); 186898184e3Ssthenok($created[$ID], 'Created hash object in normal hash'); 187898184e3Ssthen$normal_hash{'obj'} = undef; 188898184e3Ssthenok($destroyed[$ID], 'Undef hash object in normal hash'); 189898184e3Ssthen 190898184e3Ssthen$normal_hash{'obj'} = HashObj->new(); 191898184e3Ssthenok($created[$ID], 'Created hash object in normal hash'); 192898184e3Ssthen$normal_hash{'obj'} = HashObj->new(); 193898184e3Ssthenok($created[$ID], 'Created hash object in normal hash'); 194898184e3Ssthenok($destroyed[$ID-1], 'Replaced hash object in normal hash'); 195898184e3Ssthen%normal_hash = (); 196898184e3Ssthenok($destroyed[$ID], 'Hash object removed from cleared normal hash'); 197898184e3Ssthen 198898184e3Ssthen$normal_hash{'obj'} = HashObj->new(); 199898184e3Ssthenok($created[$ID], 'Created hash object in normal hash'); 200898184e3Ssthenundef(%normal_hash); 201898184e3Ssthenok($destroyed[$ID], 'Hash object removed from undef normal hash'); 202898184e3Ssthen 203898184e3Ssthen# Testing with array object 204898184e3Ssthen$normal_hash{'obj'} = AryObj->new(); 205898184e3Ssthenok($created[$ID], 'Created array object in normal hash'); 206898184e3Ssthendelete($normal_hash{'obj'}); 207898184e3Ssthenok($destroyed[$ID], 'Deleted array object in normal hash'); 208898184e3Ssthen 209898184e3Ssthen$normal_hash{'obj'} = AryObj->new(); 210898184e3Ssthenok($created[$ID], 'Created array object in normal hash'); 211898184e3Ssthen$normal_hash{'obj'} = undef; 212898184e3Ssthenok($destroyed[$ID], 'Undef array object in normal hash'); 213898184e3Ssthen 214898184e3Ssthen$normal_hash{'obj'} = AryObj->new(); 215898184e3Ssthenok($created[$ID], 'Created array object in normal hash'); 216898184e3Ssthen$normal_hash{'obj'} = AryObj->new(); 217898184e3Ssthenok($created[$ID], 'Created array object in normal hash'); 218898184e3Ssthenok($destroyed[$ID-1], 'Replaced array object in normal hash'); 219898184e3Ssthen%normal_hash = (); 220898184e3Ssthenok($destroyed[$ID], 'Array object removed from cleared normal hash'); 221898184e3Ssthen 222898184e3Ssthen$normal_hash{'obj'} = AryObj->new(); 223898184e3Ssthenok($created[$ID], 'Created array object in normal hash'); 224898184e3Ssthenundef(%normal_hash); 225898184e3Ssthenok($destroyed[$ID], 'Array object removed from undef normal hash'); 226898184e3Ssthen 227898184e3Ssthen# Testing with scalar object 228898184e3Ssthen$normal_hash{'obj'} = SclrObj->new(); 229898184e3Ssthenok($created[$ID], 'Created scalar object in normal hash'); 230898184e3Ssthendelete($normal_hash{'obj'}); 231898184e3Ssthenok($destroyed[$ID], 'Deleted scalar object in normal hash'); 232898184e3Ssthen 233898184e3Ssthen$normal_hash{'obj'} = SclrObj->new(); 234898184e3Ssthenok($created[$ID], 'Created scalar object in normal hash'); 235898184e3Ssthen$normal_hash{'obj'} = undef; 236898184e3Ssthenok($destroyed[$ID], 'Undef scalar object in normal hash'); 237898184e3Ssthen 238898184e3Ssthen$normal_hash{'obj'} = SclrObj->new(); 239898184e3Ssthenok($created[$ID], 'Created scalar object in normal hash'); 240898184e3Ssthen$normal_hash{'obj'} = SclrObj->new(); 241898184e3Ssthenok($created[$ID], 'Created scalar object in normal hash'); 242898184e3Ssthenok($destroyed[$ID-1], 'Replaced scalar object in normal hash'); 243898184e3Ssthen%normal_hash = (); 244898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from cleared normal hash'); 245898184e3Ssthen 246898184e3Ssthen$normal_hash{'obj'} = SclrObj->new(); 247898184e3Ssthenok($created[$ID], 'Created scalar object in normal hash'); 248898184e3Ssthenundef(%normal_hash); 249898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from undef normal hash'); 250898184e3Ssthen 251898184e3Ssthen# Testing with shared array 252898184e3Ssthenmy @shared_ary :shared; 253898184e3Ssthen 254898184e3Ssthen# Testing with hash object 255898184e3Ssthen$shared_ary[0] = HashObj->new(); 256898184e3Ssthenok($created[$ID], 'Created hash object in shared array'); 257898184e3Ssthendelete($shared_ary[0]); 258898184e3Ssthenok($destroyed[$ID], 'Deleted hash object in shared array'); 259898184e3Ssthen 260898184e3Ssthen$shared_ary[0] = HashObj->new(); 261898184e3Ssthenok($created[$ID], 'Created hash object in shared array'); 262898184e3Ssthen$shared_ary[0] = undef; 263898184e3Ssthenok($destroyed[$ID], 'Undef hash object in shared array'); 264898184e3Ssthen 265898184e3Ssthen$shared_ary[0] = HashObj->new(); 266898184e3Ssthenok($created[$ID], 'Created hash object in shared array'); 267898184e3Ssthen$shared_ary[0] = HashObj->new(); 268898184e3Ssthenok($created[$ID], 'Created hash object in shared array'); 269898184e3Ssthenok($destroyed[$ID-1], 'Replaced hash object in shared array'); 270898184e3Ssthen@shared_ary = (); 271898184e3Ssthenok($destroyed[$ID], 'Hash object removed from cleared shared array'); 272898184e3Ssthen 273898184e3Ssthen$shared_ary[0] = HashObj->new(); 274898184e3Ssthenok($created[$ID], 'Created hash object in shared array'); 275898184e3Ssthenundef(@shared_ary); 276898184e3Ssthenok($destroyed[$ID], 'Hash object removed from undef shared array'); 277898184e3Ssthen 278898184e3Ssthen# Testing with array object 279898184e3Ssthen$shared_ary[0] = AryObj->new(); 280898184e3Ssthenok($created[$ID], 'Created array object in shared array'); 281898184e3Ssthendelete($shared_ary[0]); 282898184e3Ssthenok($destroyed[$ID], 'Deleted array object in shared array'); 283898184e3Ssthen 284898184e3Ssthen$shared_ary[0] = AryObj->new(); 285898184e3Ssthenok($created[$ID], 'Created array object in shared array'); 286898184e3Ssthen$shared_ary[0] = undef; 287898184e3Ssthenok($destroyed[$ID], 'Undef array object in shared array'); 288898184e3Ssthen 289898184e3Ssthen$shared_ary[0] = AryObj->new(); 290898184e3Ssthenok($created[$ID], 'Created array object in shared array'); 291898184e3Ssthen$shared_ary[0] = AryObj->new(); 292898184e3Ssthenok($created[$ID], 'Created array object in shared array'); 293898184e3Ssthenok($destroyed[$ID-1], 'Replaced array object in shared array'); 294898184e3Ssthen@shared_ary = (); 295898184e3Ssthenok($destroyed[$ID], 'Array object removed from cleared shared array'); 296898184e3Ssthen 297898184e3Ssthen$shared_ary[0] = AryObj->new(); 298898184e3Ssthenok($created[$ID], 'Created array object in shared array'); 299898184e3Ssthenundef(@shared_ary); 300898184e3Ssthenok($destroyed[$ID], 'Array object removed from undef shared array'); 301898184e3Ssthen 302898184e3Ssthen# Testing with scalar object 303898184e3Ssthen$shared_ary[0] = SclrObj->new(); 304898184e3Ssthenok($created[$ID], 'Created scalar object in shared array'); 305898184e3Ssthendelete($shared_ary[0]); 306898184e3Ssthenok($destroyed[$ID], 'Deleted scalar object in shared array'); 307898184e3Ssthen 308898184e3Ssthen$shared_ary[0] = SclrObj->new(); 309898184e3Ssthenok($created[$ID], 'Created scalar object in shared array'); 310898184e3Ssthen$shared_ary[0] = undef; 311898184e3Ssthenok($destroyed[$ID], 'Undef scalar object in shared array'); 312898184e3Ssthen 313898184e3Ssthen$shared_ary[0] = SclrObj->new(); 314898184e3Ssthenok($created[$ID], 'Created scalar object in shared array'); 315898184e3Ssthen$shared_ary[0] = SclrObj->new(); 316898184e3Ssthenok($created[$ID], 'Created scalar object in shared array'); 317898184e3Ssthenok($destroyed[$ID-1], 'Replaced scalar object in shared array'); 318898184e3Ssthen@shared_ary = (); 319898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from cleared shared array'); 320898184e3Ssthen 321898184e3Ssthen$shared_ary[0] = SclrObj->new(); 322898184e3Ssthenok($created[$ID], 'Created scalar object in shared array'); 323898184e3Ssthenundef(@shared_ary); 324898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from undef shared array'); 325898184e3Ssthen 326898184e3Ssthen# Testing with shared hash 327898184e3Ssthenmy %shared_hash :shared; 328898184e3Ssthen 329898184e3Ssthen# Testing with hash object 330898184e3Ssthen$shared_hash{'obj'} = HashObj->new(); 331898184e3Ssthenok($created[$ID], 'Created hash object in shared hash'); 332898184e3Ssthendelete($shared_hash{'obj'}); 333898184e3Ssthenok($destroyed[$ID], 'Deleted hash object in shared hash'); 334898184e3Ssthen 335898184e3Ssthen$shared_hash{'obj'} = HashObj->new(); 336898184e3Ssthenok($created[$ID], 'Created hash object in shared hash'); 337898184e3Ssthen$shared_hash{'obj'} = undef; 338898184e3Ssthenok($destroyed[$ID], 'Undef hash object in shared hash'); 339898184e3Ssthen 340898184e3Ssthen$shared_hash{'obj'} = HashObj->new(); 341898184e3Ssthenok($created[$ID], 'Created hash object in shared hash'); 342898184e3Ssthen$shared_hash{'obj'} = HashObj->new(); 343898184e3Ssthenok($created[$ID], 'Created hash object in shared hash'); 344898184e3Ssthenok($destroyed[$ID-1], 'Replaced hash object in shared hash'); 345898184e3Ssthen%shared_hash = (); 346898184e3Ssthenok($destroyed[$ID], 'Hash object removed from cleared shared hash'); 347898184e3Ssthen 348898184e3Ssthen$shared_hash{'obj'} = HashObj->new(); 349898184e3Ssthenok($created[$ID], 'Created hash object in shared hash'); 350898184e3Ssthenundef(%shared_hash); 351898184e3Ssthenok($destroyed[$ID], 'Hash object removed from undef shared hash'); 352898184e3Ssthen 353898184e3Ssthen# Testing with array object 354898184e3Ssthen$shared_hash{'obj'} = AryObj->new(); 355898184e3Ssthenok($created[$ID], 'Created array object in shared hash'); 356898184e3Ssthendelete($shared_hash{'obj'}); 357898184e3Ssthenok($destroyed[$ID], 'Deleted array object in shared hash'); 358898184e3Ssthen 359898184e3Ssthen$shared_hash{'obj'} = AryObj->new(); 360898184e3Ssthenok($created[$ID], 'Created array object in shared hash'); 361898184e3Ssthen$shared_hash{'obj'} = undef; 362898184e3Ssthenok($destroyed[$ID], 'Undef array object in shared hash'); 363898184e3Ssthen 364898184e3Ssthen$shared_hash{'obj'} = AryObj->new(); 365898184e3Ssthenok($created[$ID], 'Created array object in shared hash'); 366898184e3Ssthen$shared_hash{'obj'} = AryObj->new(); 367898184e3Ssthenok($created[$ID], 'Created array object in shared hash'); 368898184e3Ssthenok($destroyed[$ID-1], 'Replaced array object in shared hash'); 369898184e3Ssthen%shared_hash = (); 370898184e3Ssthenok($destroyed[$ID], 'Array object removed from cleared shared hash'); 371898184e3Ssthen 372898184e3Ssthen$shared_hash{'obj'} = AryObj->new(); 373898184e3Ssthenok($created[$ID], 'Created array object in shared hash'); 374898184e3Ssthenundef(%shared_hash); 375898184e3Ssthenok($destroyed[$ID], 'Array object removed from undef shared hash'); 376898184e3Ssthen 377898184e3Ssthen# Testing with scalar object 378898184e3Ssthen$shared_hash{'obj'} = SclrObj->new(); 379898184e3Ssthenok($created[$ID], 'Created scalar object in shared hash'); 380898184e3Ssthendelete($shared_hash{'obj'}); 381898184e3Ssthenok($destroyed[$ID], 'Deleted scalar object in shared hash'); 382898184e3Ssthen 383898184e3Ssthen$shared_hash{'obj'} = SclrObj->new(); 384898184e3Ssthenok($created[$ID], 'Created scalar object in shared hash'); 385898184e3Ssthen$shared_hash{'obj'} = undef; 386898184e3Ssthenok($destroyed[$ID], 'Undef scalar object in shared hash'); 387898184e3Ssthen 388898184e3Ssthen$shared_hash{'obj'} = SclrObj->new(); 389898184e3Ssthenok($created[$ID], 'Created scalar object in shared hash'); 390898184e3Ssthen$shared_hash{'obj'} = SclrObj->new(); 391898184e3Ssthenok($created[$ID], 'Created scalar object in shared hash'); 392898184e3Ssthenok($destroyed[$ID-1], 'Replaced scalar object in shared hash'); 393898184e3Ssthen%shared_hash = (); 394898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from cleared shared hash'); 395898184e3Ssthen 396898184e3Ssthen$shared_hash{'obj'} = SclrObj->new(); 397898184e3Ssthenok($created[$ID], 'Created scalar object in shared hash'); 398898184e3Ssthenundef(%shared_hash); 399898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from undef shared hash'); 400898184e3Ssthen 401898184e3Ssthen# Testing with shared scalar 402898184e3Ssthen{ 403898184e3Ssthen my $shared_scalar : shared; 404898184e3Ssthen # Use a separate thread to make sure we have no private SV 405898184e3Ssthen async { $shared_scalar = SclrObj->new(); }->join(); 406898184e3Ssthen} 407898184e3Ssthenok($destroyed[$ID], 'Scalar object removed from shared scalar'); 408898184e3Ssthen 409b8851fccSafresh1# 410b8851fccSafresh1# RT #122950 abandoning array elements (e.g. by setting $#ary) 411b8851fccSafresh1# should trigger destructors 412b8851fccSafresh1 413b8851fccSafresh1{ 414b8851fccSafresh1 package rt122950; 415b8851fccSafresh1 416b8851fccSafresh1 my $count = 0; 417b8851fccSafresh1 sub DESTROY { $count++ } 418b8851fccSafresh1 419b8851fccSafresh1 my $n = 4; 420b8851fccSafresh1 421b8851fccSafresh1 for my $type (0..1) { 422b8851fccSafresh1 my @a : shared; 423b8851fccSafresh1 $count = 0; 424b8851fccSafresh1 push @a, bless &threads::shared::share({}) for 1..$n; 425b8851fccSafresh1 for (1..$n) { 426b8851fccSafresh1 { # new scope to ensure tmps are freed, destructors called 427b8851fccSafresh1 if ($type) { 428b8851fccSafresh1 pop @a; 429b8851fccSafresh1 } 430b8851fccSafresh1 else { 431b8851fccSafresh1 $#a = $n - $_ - 1; 432b8851fccSafresh1 } 433b8851fccSafresh1 } 434b8851fccSafresh1 ::ok($count == $_, 435b8851fccSafresh1 "remove array object $_ by " . ($type ? "pop" : '$#a=N')); 436b8851fccSafresh1 } 437b8851fccSafresh1 } 438b8851fccSafresh1 439b8851fccSafresh1 my @a : shared; 440b8851fccSafresh1 $count = 0; 441b8851fccSafresh1 push @a, bless &threads::shared::share({}) for 1..$n; 442b8851fccSafresh1 { 443b8851fccSafresh1 undef @a; # this is implemented internally as $#a = -01 444b8851fccSafresh1 } 445b8851fccSafresh1 ::ok($count == $n, "remove array object by undef"); 446b8851fccSafresh1} 447b8851fccSafresh1 448*9f11ffb7Safresh1# RT #131124 449*9f11ffb7Safresh1# Emptying a shared array creates new temp SVs. If there are no spare 450*9f11ffb7Safresh1# SVs, a new arena is allocated. shared.xs was mallocing a new arena 451*9f11ffb7Safresh1# with the wrong perl context set, meaning that when the arena was later 452*9f11ffb7Safresh1# freed, it would "panic: realloc from wrong pool" 453*9f11ffb7Safresh1# 454*9f11ffb7Safresh1 455*9f11ffb7Safresh1{ 456*9f11ffb7Safresh1 threads->new(sub { 457*9f11ffb7Safresh1 my @a :shared; 458*9f11ffb7Safresh1 push @a, bless &threads::shared::share({}) for 1..1000; 459*9f11ffb7Safresh1 undef @a; # this creates lots of temp SVs 460*9f11ffb7Safresh1 })->join; 461*9f11ffb7Safresh1 ok(1, "#131124 undef array doesnt panic"); 462*9f11ffb7Safresh1 463*9f11ffb7Safresh1 threads->new(sub { 464*9f11ffb7Safresh1 my @a :shared; 465*9f11ffb7Safresh1 push @a, bless &threads::shared::share({}) for 1..1000; 466*9f11ffb7Safresh1 @a = (); # this creates lots of temp SVs 467*9f11ffb7Safresh1 })->join; 468*9f11ffb7Safresh1 ok(1, "#131124 clear array doesnt panic"); 469*9f11ffb7Safresh1} 470b8851fccSafresh1 471b8851fccSafresh1 472898184e3Ssthen# EOF 473