New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared hash destroyed too soon #8199
Comments
From jerry@hedden.usThis is a bug report for perl from jerry@hedden.us, I am the author of the module Objects::InsideOut. That module supports Object::InsideOut keeps track of any objects created using a shared One trouble I had in reporting this is that the bug occurs The sequence of events for this code starts with: 1. A new object is created. The object ID and thread ID (= 0 for main 2. A new thread is created. The CLONE subroutine is called to add the 3. The thread exits and ->join()s with the main thread. Global cleanup The output from the code (which is below, following the code) indicates 4. The object's destructor is called as part of the cleanup for the 5. The %SHARED hash is destroyed. 6. The object's destructor is called as part of the cleanup for the There does not seem to be any workaround for this bug. It is not My (albeit ignorant) thought on how to fix this bug would be to modify ##### CODE ##### use strict; use threads; package Object::InsideOut; { my %SHARED; my $THREAD_ID = 0; my $OBJ_ID = 1; sub new my $self = \(my $scalar); lock(%SHARED); return ($self); sub DESTROY print(STDERR "Checking that the \%SHARED hash still exists in thread lock(%SHARED); my $tid = pop(@{$SHARED{$class}{$$self}}); while ($tid != $THREAD_ID) { if (@{$SHARED{$class}{$$self}}) { delete($SHARED{$class}{$$self}); sub CLONE $THREAD_ID = threads->tid(); lock(%SHARED); for my $class (keys(%SHARED)) { # IGNORE ALL THIS CHECK { my $x = 0; } # IGNORE THIS package My::Obj; { package main; my $obj = My::Obj->new(); my $thr = threads->create(sub { return; }); ##### OUTPUT ##### Checking that the %SHARED hash still exists in thread 0 Flags: Site configuration information for perl v5.8.7: Configured by Jerry at Mon Oct 24 08:03:53 EDT 2005. Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Locally applied patches: @INC for perl v5.8.7: Environment for perl v5.8.7: |
From @iabynOn Tue, Nov 08, 2005 at 10:23:58AM -0800, Jerry D. Hedden wrote:
This happens because shared arrays and hashes (due to their The issue can be duplicated without threads in the following code: #!/usr/bin/perl sub T::TIEHASH: { bless [], 'T' } tie %h, 'T'; which gives: Name "main::h" used only once: possible typo at /tmp/d1 line 7. Note that the eval is used to ensure that the ref to the blessed hash is I don't think there's anything we realistically can do to the perl -- |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Tue Nov 08 17:50:07 2005, davem@iabyn.com wrote:
Could we solve it with an extra refcount for the mg_obj, as there is for |
Migrated from rt.perl.org#37640 (status was 'open')
Searchable as RT37640$
The text was updated successfully, but these errors were encountered: