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

add check for invalid state in _growend! slow-path #53513

Merged
merged 6 commits into from
Mar 11, 2024

Conversation

oscardssmith
Copy link
Member

This only triggers in cases where the user has done something pretty bad (e.g. modified the size incorrectly, or calling push! from multiple threads on the same vector without a lock). I'm very unsure if ConcurrencyViolationError is the right error to throw here, but I think most of the time, that is going to be the cause. This check is in the slow path because adding extra checks here is basically free (since it will run rarely, and will be batched with O(n) work to copy everything over). I also only included it for growend! and not the other grow functions because almost all users doing bad things in a multithreaded context are likely only push! ing rather than inserting at the front or arbitrary locations.

@oscardssmith oscardssmith added the domain:arrays [a, r, r, a, y, s] label Feb 28, 2024
@KristofferC
Copy link
Sponsor Member

Is there something special at exactly this point? Presumably there are many places that use these fields so what is so exceptional that this should be added right here?

@oscardssmith
Copy link
Member Author

oscardssmith commented Mar 4, 2024

There aren't that many places that use these fields (there were none prior to 1.11 since the fields didn't exist). This sort of check also is only beneficial before modifications to the fields, of which there are fewer use cases. It would be possible to add this to _growbeg!, _growat!, _deletebeg!, _deleteend, and _deleteat!, but this PR only added it to _growend! since that is by far the most commonly used (especially by places like the compiler that are especially likely to be incorrectly used in multi-threading (including by the compiler). Also, the _deletebeg! and _deleteend! don't make sense to run this since they always run in O(1) so it would be relatively high overhead.

@KristofferC
Copy link
Sponsor Member

There aren't that many places that use these fields (there were none prior to 1.11 since the fields didn't exist).

Yes, heh, I meant in the new array code.

Seems at least reasonable to have it in growbeg (pushfirst!) which is also used in the compiler if this is in fact useful.

@oscardssmith
Copy link
Member Author

fair enough. Added.

@oscardssmith
Copy link
Member Author

I think this is now ready to go.

@oscardssmith oscardssmith added the domain:multithreading Base.Threads and related functionality label Mar 7, 2024
@oscardssmith oscardssmith merged commit a0cee55 into JuliaLang:master Mar 11, 2024
5 of 8 checks passed
@oscardssmith oscardssmith deleted the os/growend-invariant branch March 11, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] domain:multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants