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 function to allow checking thread type #4645

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

bboston7
Copy link
Contributor

Closes #4613

This change adds a function threadIsType function to Application that allows a thread to check its type. This is intended to support more detailed assertions than the usual releaseAssert(threadIsMain()) assertions we're currently using everywhere.

The implementation differs a bit from the proposed solution in #4613 as it uses a mapping in ApplicationImpl to track thread types, rather than using static variables. I chose this approach because as far as I can tell, it's not possible to assign a thread an id. Given that, ApplicationImpl would need to set these variables in its constructor, and the variables would hold meaningless values prior to that. I figure it's safer to ensure that thread types can only be reasoned about after the creation of the threads themselves in ApplicationImpl's constructor. However, if it's important that thread types be reasoned about without an Application or AppConnector, then I'm open to changing the design.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

@bboston7 bboston7 requested review from SirTyson and graydon February 11, 2025 21:44
@graydon graydon enabled auto-merge February 11, 2025 21:47
auto-merge was automatically disabled February 11, 2025 23:04

Head branch was pushed to by a user without write access

@bboston7 bboston7 requested a review from SirTyson February 11, 2025 23:08
Copy link
Contributor

@SirTyson SirTyson left a comment

Choose a reason for hiding this comment

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

LGTM, can you squash?

Closes stellar#4613

This change adds a function `threadIsType` function to `Application`
that allows a thread to check its type. This is intended to support more
detailed assertions than the usual `releaseAssert(threadIsMain())`
assertions we're currently using everywhere.

The implementation differs a bit from the proposed solution in stellar#4613 as
it uses a mapping in `ApplicationImpl` to track thread types, rather
than using static variables. I chose this approach because as far as I
can tell, it's not possible to assign a thread an id.  Given that,
`ApplicationImpl` would need to set these variables in its constructor,
and the variables would hold meaningless values prior to that. I figure
it's safer to ensure that thread types can only be reasoned about after
the creation of the threads themselves in `ApplicationImpl`'s
constructor. However, if it's important that thread types be reasoned
about without an `Application` or `AppConnector`, then I'm open to
changing the design.
@bboston7
Copy link
Contributor Author

can you squash?

Done

@graydon graydon enabled auto-merge February 11, 2025 23:16
@graydon graydon added this pull request to the merge queue Feb 12, 2025
Merged via the queue into stellar:master with commit 70c7d68 Feb 12, 2025
13 checks passed
@bboston7 bboston7 deleted the thread-asserts branch February 12, 2025 19:10
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.

Extending threadIsMain() assert
3 participants