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

Remove MutexID list #4002

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Remove MutexID list #4002

merged 1 commit into from
Nov 11, 2024

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Oct 30, 2024

Remove MutexID list in SynchronizationObjects to avoid memory leaks.

cc #3967

@tiif
Copy link
Contributor Author

tiif commented Oct 30, 2024

I feel I have been constantly running into already mutably borrowed: BorrowError when it comes to unblock_thread. It always takes me a while to realise that it has something to do with unblock_thread again.

Usually, the list of blocked thread ids is stored in a struct. Alternating between retrieving thread id (which involves a mutable borrow to the struct) and unblock thread will usually lead to BorrowMut error because the struct often need to be borrowed again during the unblock callback.

@RalfJung
Copy link
Member

RalfJung commented Oct 30, 2024

Generally you have to take great care of your RefCell handles. Never keep them any longer than you have to. For every function you call while holding the handle, ensure it doesn't reentrantly access the same data again.

If we didn't use RefCell, you'd get a borrow checking error due to changing a vector while iterating it. That would be nicer but unfortunately the reference patterns are too dynamic to make that work.

@tiif
Copy link
Contributor Author

tiif commented Oct 31, 2024

For every function you call while holding the handle, ensure it doesn't reentrantly access the same data again.

This is a pretty nice way to see it, thanks.

Copy link
Contributor Author

@tiif tiif left a comment

Choose a reason for hiding this comment

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

Aside from the questions in the comments, this is ready

@rustbot ready

src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/shims/unix/sync.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete labels Nov 2, 2024
@tiif tiif changed the title [WIP]: Remove MutexID list Remove MutexID list Nov 2, 2024
@tiif tiif marked this pull request as ready for review November 2, 2024 21:11
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Thanks, looks great overall! But there's a bunch of minor things.

src/concurrency/sync.rs Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Show resolved Hide resolved
src/shims/unix/sync.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Nov 9, 2024

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 9, 2024
@tiif
Copy link
Contributor Author

tiif commented Nov 10, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 10, 2024
src/concurrency/sync.rs Outdated Show resolved Hide resolved
src/shims/unix/sync.rs Outdated Show resolved Hide resolved
src/concurrency/sync.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

Just some final nits. :)
You can squash after taking care of those (with --keep-base as usual).

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 10, 2024
@tiif
Copy link
Contributor Author

tiif commented Nov 10, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 10, 2024
@RalfJung RalfJung added this pull request to the merge queue Nov 11, 2024
@RalfJung
Copy link
Member

Oh, wtf... as long as there is a "requested changes" review, it won't merge, even if the merge button is pressed by the person that requested the changes...

Merged via the queue into rust-lang:master with commit b791b29 Nov 11, 2024
7 checks passed
@tiif tiif deleted the leakythread branch November 18, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants