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

Fix a race in ClassHOW new_type #4482

Merged
merged 2 commits into from
Jul 30, 2021
Merged

Conversation

vrurg
Copy link
Member

@vrurg vrurg commented Jul 28, 2021

Anonymous class ID is storead in a class my variable and was incremented by new_type method without a lock protection. In my testing the probablity of creating a clashing name was ~0.25% for concurrently invoked new_type methods.

Anonymous class ID is storead in a class `my` variable and was
incremented by `new_type` method without a lock protection. In my
testing the probablity of creating a clashing name was ~0.25% for
concurrently invoked `new_type` methods.
$metaclass.set_name($obj, $name // "<anon|{$anon_id++}>");
$id_lock.protect: {
$metaclass.set_name($obj, $name // "<anon|{$anon_id++}>");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably won't make a difference, but you could improve parallelization by only protecting $anon_id++ like in

$lock.protect({ $count++ })

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but how much sense does it make? The current way is more readable.

In either case, nqp::cas_i would be even better here, but NQP seemingly doesn't support it.

Minor performance improvement. Especially for cases where class name is
provided.
@vrurg vrurg merged commit b7f088b into rakudo:master Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants