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
Make usage of stateful patterns thread-safe #2633
Conversation
This wouldn't work if the patterns are nested within another pattern. We ought to create an AbstractDelegatePattern and override fork in there and ensure all patterns with nested patterns utilise this |
Good point, I'll look into it. |
I went for an interface Let me know what you think. |
This might also be relevant for #2626, I'm just not sure what to expect from that pattern in a multi-threaded setting |
Are there definitely no further instances where pattern might not necessarily get forked here? |
I'll have to go through the WE patterns again, it seems there are a few more |
Went through the impls again, should be all now hopefully. |
Is there much of a point in having the new interface? If a new pattern that would use it is created then either we remember the interface or we don't (same chances as overriding the fork method tbh) |
I thought about forking some of the patterns only if the inner patterns need to be forked, in which case it was somewhat useful as a marker interface, but I decided against the additional checking overhead, so I guess it can be removed again. |
@Override | ||
public Pattern fork() { | ||
RelativePattern forked = new RelativePattern(this.pattern.fork(), this.minY, this.maxY); | ||
forked.origin = this.origin; // maintain origin for forks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably look at having the origin be toImmutable()
ised when it's set (for this and any other patterns)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would otherwise already cause bugs I think? But yeah, that might make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, but can't be too careful aha
Overview
Description
Some patterns make use of
MutableBlockVector
or might delegate to patterns that might do so, therefore we need to fork it to prevent race conditions.The example command
//set #!z[#linear2d[white_wool,2%light_gray_wool,4%gray_wool,8%black_wool]]
and how it looks:Before:
With this change:
Submitter Checklist
@since TODO
.