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

Fix SetThreadName on Linux #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

norihiro
Copy link

@norihiro norihiro commented Jun 26, 2022

Description

SetThreadName set the name of current thread, where it is expected to set the target thread. This change will store the name if the thread is not started. Then, set the name after the thread is created.

The original code uses prctl to set the name. However, the cast to unsigned long will loose the upper 32-bit of the 64-bit pointer on 64-bit system. This PR also fix to use pthread_setname_np to fix the issue.

int ret = prctl(PR_SET_NAME, (unsigned long)name, 0, 0);

Step to reproduce the issue

OS: Fedora Linux 34

  1. Start OBS Studio with AJA
  2. Start AJA Output on OBS Studio
  3. Run top

Without this fix, top shows AJA Video Outpu as the name of the main thread of OBS Studio.
With this fix, top shows the original name of the thread. When hit H, still AJA Video Outpu appears as another thread.

SetThreadName set the name of current thread, where it is expected to
set the target thread. This change will store the name if the thread is
not started. Then, set the name after the thread is created.

Also fix missing upper 32-bit of the pointer on AMD64.
@norihiro norihiro force-pushed the fix-set-thread-name branch from 1503e85 to 33048cb Compare June 26, 2022 17:45
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.

1 participant