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

'does' is not threadsafe #6361

Closed
p6rt opened this issue Jun 26, 2017 · 4 comments
Closed

'does' is not threadsafe #6361

p6rt opened this issue Jun 26, 2017 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 26, 2017

Migrated from rt.perl.org#131654 (status was 'rejected')

Searchable as RT131654$

@p6rt
Copy link
Author

p6rt commented Jun 26, 2017

From @BenGoldberg1

Here's an IRC snippet showing the problem​:

<BenGoldberg> m​: await start { my $a = "strange"; $a does role Test { }; } xx 16
<+camelia> rakudo-moar 9936a3​: OUTPUT​: «Tried to get the result of a broken Promise␤ in block <unit> at <tmp> line 1␤␤Original exception​:␤ Incompatible MROs in P6opaque rebless for types Str+{Test} and Str+{Test}␤ in block at <tmp> line 1␤␤»

Using a Lock solves the problem, but there ought to be a better solution.

<BenGoldberg> m​: my $l = Lock.new; await start { my $a = "dubba"; role Test { }; $l.protect​: { $a does Test }; } xx 16
<+camelia> rakudo-moar 9936a3​: ( no output )

@p6rt
Copy link
Author

p6rt commented Jun 26, 2017

From @jnthn

On Sun, 25 Jun 2017 23​:14​:00 -0700, ben-goldberg@​hotmail.com wrote​:

Here's an IRC snippet showing the problem​:

<BenGoldberg> m​: await start { my $a = "strange"; $a does role Test {
}; } xx 16
<+camelia> rakudo-moar 9936a3​: OUTPUT​: «Tried to get the result of a
broken Promise␤ in block <unit> at <tmp> line 1␤␤Original exception​:␤
Incompatible MROs in P6opaque rebless for types Str+{Test} and
Str+{Test}␤ in block at <tmp> line 1␤␤»

Using a Lock solves the problem, but there ought to be a better
solution.

<BenGoldberg> m​: my $l = Lock.new; await start { my $a = "dubba"; role
Test { }; $l.protect​: { $a does Test }; } xx 16
<+camelia> rakudo-moar 9936a3​: ( no output )

I think you wanted `but`. `does` is in-place, and you're therefore in-place mutating a string from the constant table in this case and that will have global effect on the program. Such things will likely at some point become an error. Note that if this was successful, it would be applying the role Test to the same thing 16 times.

It's easy to remember which of the in-place mutation operators in Perl 6 are threadsafe, because none of them are (does, ++, --, the = meta-operator, and so forth).

So, rejecting as it was never intended that concurrently mixing in to the same object without any kind of protection would work out, and the original code is probably confused and wanted to use `but` anyway.

/jnthn

@p6rt
Copy link
Author

p6rt commented Jun 26, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 26, 2017

@jnthn - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Jun 26, 2017
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant