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

Improve/fix named threads #131

Merged
merged 8 commits into from
Aug 24, 2022
Merged

Improve/fix named threads #131

merged 8 commits into from
Aug 24, 2022

Conversation

BlackMark29A
Copy link

This PR addresses two issues regarding named threads:

  • The main thread was named cy-main, however, user code running in the main thread could spawn new threads, which would then inherit the same name, leading to more than one cy-main thread. This behavior is probably more confusing than useful and this PR thus no longer gives the main thread a special name.
  • On macOS the pthread_setname_np function used to set the name of threads has a different signature than on linux. This in and of itself is not an issue, however, the macOS version can only set the name of the calling thread, which is incompatible with the way celerity currently implements named threads. Therefore this PR adds a feature flag CELERITY_FEATURE_NAMED_THREADS to disable the feature entirely on macOS.

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@PeterTh PeterTh left a comment

Choose a reason for hiding this comment

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

I feel like it would make more sense to use the #if CELERITY_FEATURE_NAMED_THREADS to define or stub out set_thread_name, rather than doing it at every call site. This keeps the general code (where the call sites are) cleaner.

@BlackMark29A
Copy link
Author

I wanted to not use a feature flag at all and so my first implementation had a similar idea of having a third stub implementation that would just print a warning that the feature was unsupported, however that obviously didn't work for the unit tests and so I added the feature flag.

I like the idea of keeping the call-sites unchanged, so I'll move the feature flag inside the implementation.

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@fknorr fknorr left a comment

Choose a reason for hiding this comment

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

Feature detection macros were originally intended for public APIs, like celerity::local_accessor. This would be a new use for purely internal considerations.

We have a workaround for a similar problem when querying the affinity mask, which apple does not implement the way we want either. There, we exclude the translation unit affinity.unix.cc and use a #ifdef __APPLE__ at the call site.

Without clearly preferring one over the other, these two cases should be handled in a similar manner.

@BlackMark29A
Copy link
Author

I did not know feature detection macros were intended to be public, in that case if we decide to keep them for this use case we should clearly mark them as being INTERNAL or PRIVATE or DETAIL.

As @PeterTh already pointed out it is cleaner to keep the call-sites unchanged, which I agree with. As for using __APPLE__ vs a feature detection macro, I would say it depends. Inside named_threads.unix.cc I would actually prefer __APPLE__, as this relates to platform specific code, however for disabling the unit test I think using CELERITY_(INTERNAL)_FEATURE_NAMED_THREADS is better, because the unit test doesn't use any platform specific code, and so disabling it based on feature availability makes more sense to me, especially since the decision whether the feature is available or not is actually made by the build system, and not by the unit test implementation.

Thoughts?

@fknorr
Copy link
Contributor

fknorr commented Aug 3, 2022

There is precedence for CELERITY_DETAIL_ in macros.

@github-actions
Copy link

github-actions bot commented Aug 3, 2022

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link

github-actions bot commented Aug 3, 2022

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@fknorr fknorr left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@psalz psalz left a comment

Choose a reason for hiding this comment

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

One minor remark, otherwise LGTM! Please squash before merging.

cmake/celerity-config.cmake.in Outdated Show resolved Hide resolved
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@BlackMark29A BlackMark29A force-pushed the improve-named-threads branch from 43b816f to a8433d8 Compare August 24, 2022 11:24
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@BlackMark29A BlackMark29A merged commit ff5fbec into master Aug 24, 2022
@BlackMark29A BlackMark29A deleted the improve-named-threads branch August 24, 2022 12:11
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.

4 participants