Skip to content

Add thread name back in #21791

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

Open
wants to merge 18 commits into
base: devel
Choose a base branch
from

Conversation

jvolmer
Copy link
Contributor

@jvolmer jvolmer commented May 29, 2025

PR got rid of printing the involved thread names in the async registry due to a bug. This PR adds the thread name back in, but now we directly save the thread name string when creating the ThreadInfo object that includes all needed thread infos for the async registry. We use this ThreadInfo object several times. To save the object - and therefore the string - only once, we wrap the ThreadInfo object into a shared resource object. A ThreadInfo instance is deleted when all its references are gone.

With this PR we use the shared ThreadInfo resource in two places of a promise in the async registry:

  1. the owning thread of a promise (this is set during creation of the promise and never changes)
  2. the parent of a promise, which can either be another Promise or another thread: this parent can change during the lifetime of the promise, therefore we have to take care of synchronization because the promise can be read and changed at the same time. The async registry needs to be highly performant - because it will be used everywhere in the code, therefore we need a lock-free synchronization here.

Due to these requirements, the PR adds a new SharedResource that now wraps the ThreadInfo and has an atomic reference counter.
For 1. we don't need any synchronization, therefore the owning thead is a SharedPtr, which only takes care of properly incrementing and decrementing the reference counter of the SharedResource.
For 2. we need synchronization and we wrote our own AtomicSharedOrRawPtr, wich is a lock-free either-or type that includes an atomic pointer to either a SharedResource or a raw pointer (which in our case is a void pointer - we identify a promise by its this pointer and cast that - due to usability reasons - to a void ptr. This PR actually wraps this void ptr now into a PromiseId type to make it a bit better readable).

There is now one more member in a promise that needs to reference the new ThreadInfo: The running_thread currently still uses the old ThreadId type that does not include a thread name string. This will be part of another PR.

@jvolmer jvolmer self-assigned this May 29, 2025
@cla-bot cla-bot bot added the cla-signed label May 29, 2025
Copy link
Contributor

@jbajic jbajic left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

2 participants