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

Tweak SemaphoreDisposer to null out the held semaphore #57831

Conversation

jasonmalinowski
Copy link
Member

While investigating a deadlock, it would have been made the analysis easier if we null out the semaphore once we've released it, because it means the then one-and-only instance of a SemaphoreDisposer that points to the semaphore is the one that is holding the lock.

While investigating a deadlock, it would have been made the analysis
easier if we null out the semaphore once we've released it, because
it means the then one-and-only instance of a SemaphoreDisposer that
points to the semaphore is the one that is holding the lock.
// async deadlock where a SemaphoreSlim is held but you're unsure why, as long all the users of the
// SemaphoreSlim used the Disposable helpers, you can search memory and find the instance that
// is pointing to the SemaphoreSlim that hasn't nulled out this field yet; in that case you know
// that's holding the lock and can figure out who is holding that SemaphoreDisposer.
Copy link
Member

Choose a reason for hiding this comment

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

we're in a struct. so this does only work as long as the NonCopyable part above really is maintained. i can allow this :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@CyrusNajmabadi Indeed, the [NonCopyable] being violated does mean we could end up with "surprises", but at this point, this is the least of your concerns IMHO. 😄

Copy link
Member

@jaredpar jaredpar Nov 18, 2021

Choose a reason for hiding this comment

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

so this does only work as long as the NonCopyable part above really is maintained

Instances of this type are copied twice in this very file so [NonCopyable] is more like [NonCopyableForSomeVersionsOfCopy]

Copy link
Member

@sharwell sharwell Nov 18, 2021

Choose a reason for hiding this comment

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

Instances of this type are copied twice in this very file

There are no copies of this type in this file (moves are not copies). A copy is a case where the new location and the old location can still be accessed with the value; the analyzer ideally would ignore cases where the old location is accessible but never accessed, but it doesn't pay attention to that right now.

Copy link
Member

Choose a reason for hiding this comment

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

There are two returns which are copies. You label them moves but that doesn't change that copies occur.

@333fred
Copy link
Member

333fred commented Nov 18, 2021

@jasonmalinowski compiler code needs 2 sign offs from the team

@jasonmalinowski
Copy link
Member Author

@333fred Oops, thanks. I was staring at this going "oh, I should get a second compiler review" and didn't realize I had already set auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants