Home > Archive > ithreads > November 2007 > [PATCH] Bug fix for storing shared objects in shared structures
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[PATCH] Bug fix for storing shared objects in shared structures
|
|
| Jerry D. Hedden 2007-11-06, 7:34 pm |
| The attached patches fix this bug. Thank to Dean Arnold for the
suggestion to use a PL_ function pointer.
Jerry D. Hedden wrote:
> I'm trying to come up with a fix for the bug related to
> storing shared objects inside of shared structures. The bug
> is that when any proxy objects for the shared object are
> destroyed, the object's DESTROY routine is called even
> thought the object itself should not yet be destroyed.
>
> The following elicits the bug:
> -----
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use threads;
> use threads::shared;
>
> package Jar; {
> my @jar :shared;
>
> sub new {
> bless(&threads::shared::share({}), shift);
> }
>
> sub store {
> my ($self, $cookie) = @_;
> push(@jar, $cookie);
> print("JAR : Cookie stored\n");
> return $jar[-1]; # BUG: The cookie is destroyed here
> }
> }
>
> package Cookie; {
> my $destruction_count = 0;
>
> sub new {
> bless(&threads::shared::share({}), shift);
> }
>
> sub DESTROY {
> $destruction_count++;
> print("COOKIE: destruction count = $destruction_count\n");
> }
> }
>
> package main;
>
> MAIN:
> {
> my $jar = Jar->new();
> my $cookie = Cookie->new();
>
> print("MAIN : Storing cookie\n");
> $jar->store($cookie);
>
> print("\nMAIN : Cookie should not have been destroyed yet\n");
>
> print("\nMAIN : Exiting scope\n")
> }
>
> print("\nDONE\n");
> -----
> The above outputs:
> MAIN : Storing cookie
> JAR : Cookie stored
> COOKIE: destruction count = 1
>
> MAIN : Cookie should not have been destroyed yet
>
> MAIN : Exiting scope
> COOKIE: destruction count = 2
>
> DONE
>
> which shows that DESTROY is called twice - the first time by
> the destruction of a proxy object.
>
> I am attempting to fix this bug by first providing a call in
> threads::shared (ext/threads/shared/shared.xs) to report on
> whether or not a shared object should be destroyed: If the
> ref is shared, and its refcnt is greater than one, then it
> should NOT be destroyed.
| |
| Jerry D. Hedden 2007-11-06, 10:29 pm |
| On 11/6/07, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
> On 06/11/2007, Jerry D. Hedden <jdhedden@cpan.org> wrote:
>
> OK. The blead.patch can go in without problems: it does nothing and
> prepares binary compatibilty for upcoming 5.10.x and upcoming CPAN
> releases of threads::shared. But the shared.patch itself might be a
> bit dangerous to put in bleadperl this late, knowing that it could
> always be upgraded from CPAN ? What do you think ?
I plan to release the updated threads::shared to CPAN if you
incorporate these patches into blead. However, there is no
compatibility issues: the two patches will work with or without each
other. You can see this by noting the #ifdef PL_destroyhook in
shared.xs.
| |
| Jerry D. Hedden 2007-11-06, 10:29 pm |
| On 11/6/07, Jerry D. Hedden <jdhedden@cpan.org> wrote:
> On 11/6/07, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
>
> I plan to release the updated threads::shared to CPAN if you
> incorporate these patches into blead. However, there is no
> compatibility issues: the two patches will work with or without each
> other. You can see this by noting the #ifdef PL_destroyhook in
> shared.xs.
In fact, I just uploaded threads::shared 1.15 to CPAN. :)
| |
| Jerry D. Hedden 2007-11-08, 4:41 am |
| Jerry D. Hedden wrote:
> The attached patches fix this bug. Thank to Dean Arnold for the
> suggestion to use a PL_ function pointer.
Dean Arnold wrote:
> Just to double check: does this permit *any*
> blessed, tied SV to make use of this feature
> (assuming it's tie module chains the PL_destroyhook) ?
I believe so.
> Or only if ithreads is configured ?
I didn't put in any ithreads conditionals so that shouldn't
prevent its use.
> My read of the code indicates it does,
> which means I can borrow it for Thread::Sociable...and
> perhaps DBI (which has blessed, tied hashes) might as well ?
Good luck.
| |
| Rafael Garcia-Suarez 2007-11-08, 8:26 am |
| On 06/11/2007, Jerry D. Hedden <jdhedden@cpan.org> wrote:
> On 11/6/07, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
>
> I plan to release the updated threads::shared to CPAN if you
> incorporate these patches into blead. However, there is no
> compatibility issues: the two patches will work with or without each
> other. You can see this by noting the #ifdef PL_destroyhook in
> shared.xs.
OK, I've applied the blead.patch part as #32241 to bleadperl.
| |
| Rafael Garcia-Suarez 2007-11-08, 8:26 am |
| On 08/11/2007, Jerry D. Hedden <jdhedden@cpan.org> wrote:
> I'm sorry if I've things, but the threads::shared patch is a
> patch to update blead to threads::shared v1.15. It's an official
> module update patch to blead.
Yes, I understood that. But given that we're trying to be in code
freeze, (except for the latest CPANPLUS / Module::Build VMS
portability patches, and some internal tweaks or severe bug fixes),
given also that threads::shared is now dual-lived and upgradeable
separately, and given that I prefer avoiding breaking the smokes, I
think I'll apply threads.patch only if I'm really convinced it's
release critical.
| |
| Jerry D. Hedden 2007-11-08, 8:26 am |
| I'm sorry if I've things, but the threads::shared patch is a
patch to update blead to threads::shared v1.15. It's an official
module update patch to blead.
> OK, I've applied the blead.patch part as #32241 to bleadperl.
|
|
|
|
|