-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear list,

while playing with ithreads and shared data structures, perl crashed.

(Perl 5.8.4 and 5.8.2 on FreeBSD 5.2 with ithreads, perl -V in the attached 
example code; also tested with Perl 5.8.4 and 5.8.0 on Linux 2.4.)

Attached is a test script, which crashes when using shared data.
This is the data structure which I want to implement and share between
different threads,so that every thread can access and modify this data:

my $dummy_unshared = 
   {
   arrayref    => 
      [
         { foo => "bar 1" },
         { foo => "bar 2" },
         { foo => "bar 3" },
      ]
   };


When starting a new Thread for each element in the array and adding or 
changing the corresponding hash, perl crashes. The thread must be detached
or joined.

It is not neccessary to pass the hashref to the thread or access the data
inside the thread.

   foreach my $hashref (@{ $dummy->{arrayref} }) 
      {
      # The following line causes perl to crash, when the data structure 
      # is shared
      $hashref->{status} = "some text";
      
      # start and detach thread
      threads->new(\&thread)->detach; 
      
      }

I realised that the address of the hashref in 
direct access is different to hashref access, but the values in the
data structure look like they are correct.

   print "Direct access:     $dummy->{arrayref}[$i]\n";
   print "Access by hashref: $hashref\n";
 
   # The following line let perl crash, when the data structure is shared
   $hashref->{status} = "some text $i";
   
   print "Dump if direct access:",  Dumper($dummy->{arrayref}[$i]);
   print "Dump of hashref access:", Dumper($hashref);
   print "Complete dummy: ",        Dumper($dummy);

The result:

- --- SNIP -----------

Direct access:     HASH(0x80640a8)
Access by hashref: HASH(0x811d390)

Dump if direct access:$VAR1 = {
          'foo' => 'bar 1',
          'status' => 'some text 0'
        };
Dump of hashref access:$VAR1 = {
          'foo' => 'bar 1',
          'status' => 'some text 0'
        };
Complete dummy: $VAR1 = {
          'arrayref' => [
                          {
                            'foo' => 'bar 1',
                            'status' => 'some text 0'
                          },
                          {
                            'foo' => 'bar 2'
                          },
                          {
                            'foo' => 'bar 3'
                          }
                        ]
        };
Direct access:     HASH(0x80640a8)
Access by hashref: HASH(0x811d818)

Bus error (core dumped)

- --- SNAP ----------


Because different timing, the crash occures every time at a different 
position.


Is this a bug in perl or in the script?!? 


Thank you!


Ciao
  Alvar



- -- 
** Alvar C.H. Freude -- http://alvar.a-blast.org/ -- http://odem.org/
** Berufsverbot? http://odem.org/aktuelles/staatsanwalt.de.html
** ODEM.org-Tour: http://tour.odem.org/
**�5 Jahre Blaster:�http://www.a-blast.de/ | http://www.a-blast.de/statistik/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAq4aaOndlH63J86wRAu2JAJ9d950vaOIG6xjqoB82YRlf2PnhRgCgzMU8
94LA2rzsc1Ky4i771tmcyqc=
=MKaH
-----END PGP SIGNATURE-----

Attachment: crash_threads_shared-test.pl
Description: Binary data

Attachment: pgpJnLCzF9PXR.pgp
Description: PGP signature

Reply via email to