Skip to content
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

Clone::clone on shared data causes crash [rt.cpan.org #93821] #18

Open
atoomic opened this issue Oct 25, 2018 · 1 comment
Open

Clone::clone on shared data causes crash [rt.cpan.org #93821] #18

atoomic opened this issue Oct 25, 2018 · 1 comment
Labels
bug Need Help need some feedback or help

Comments

@atoomic
Copy link
Collaborator

atoomic commented Oct 25, 2018

Migrated from rt.cpan.org#93821 (status was 'open')

Requestors:

From [email protected] on 2014-03-13 05:13:10:

Hi,

I'm trying to use Clone::clone to copy a hash which is shared among threads,
but when the result is accessed, Perl dies with
"Can't locate object method "FETCH" via package "threads::shared::tie" 
at ..."

Here's an example:
#!/usr/bin/perl
use strict; use warnings;
use threads;
use threads::shared;
use Clone;

my $a = shared_clone { foo => 100, bar => 200 };
my $b = Clone::clone($a);
print $b->{foo}, "\n"; #crashes here

-Jim

From [email protected] on 2014-05-15 22:16:59:

Hi Jim,

I don't think Clone is thread-safe. Are you able to reproduce the issue if you use Storable's dclone() instead of Clone's clone()?

Thanks!

From [email protected] on 2014-05-15 23:31:38:

On 05/15/2014 03:16 PM, Breno G. de Oliveira via RT wrote:
| I don't think Clone is thread-safe.
| Are you able to reproduce the issue if you use Storable's dclone() 
instead of Clone's clone()?

I'm not familiar with Storable, but gave it a try.   The result of 
dclone() can not be
de-referenced either, but the error is different:
#!/usr/bin/perl
use strict; use warnings; use threads; use threads::shared;
use Storable qw(dclone);

my $a = shared_clone { foo => 100, bar => 200 };
my $b = dclone($a);
# The next statement crashes with:
# Can't locate object method "FETCH" via package "threads::shared::tie"
print $b->{foo}, "\n";

From [email protected] on 2015-11-06 16:20:09:

Unfortunately threads::shared implements the sharing with tie-s to threads::shared::tie, but it makes zero sense to have a clone take part in the sharing -- if you wanted that, you would use the original variable, not the clone... Clone and Storable will (dirtily) have to special case that an remove all tie-s to threads::shared::tie, to be able to cooperate with threads::shared. Note that threads::shared itself has the same problem, you can't send a structure over a Thread::Queue and return the sent object over this or another Threads::Queue, this will crash after one or more iterations (I don't remember).

Ralf

From [email protected] on 2015-11-06 16:32:17:

https://rt.perl.org/Public/Bug/Display.html?id=38443

Date:	Mon, 06 Feb 2006 16:43:36 +0100

:)

@atoomic atoomic added bug Need Help need some feedback or help labels Oct 25, 2018
@atoomic
Copy link
Collaborator Author

atoomic commented Oct 25, 2018

I'm not familiar with threads would appreciate some external feedback on this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Need Help need some feedback or help
Projects
None yet
Development

No branches or pull requests

1 participant