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

#1792 Centralized the use of pthread_create and thread_setname in the create_thread_with_name function that uses thread_wrapper for compatibility across platforms and with Linux GLIBC<2.12 #1022

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adjusted thread_setname usage compatibility for FreeBSD using pthread…
…_set_name_np from pthread_np.h, solution proposed by @devnexen. #952
  • Loading branch information
fabiodepin committed Apr 6, 2023
commit ab9528319fdefb82e852abc47731cba5502957bc
5 changes: 5 additions & 0 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#ifdef __linux__
#include <sys/prctl.h>
#endif
#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif

#include "queue.h"

Expand Down Expand Up @@ -648,6 +651,8 @@ static void thread_setname(pthread_t thread, const char *name) {
fprintf(stderr, "Threads other than the caller cannot be renamed [%s].", name);
}
#endif
#elif defined(__FreeBSD__)
pthread_set_name_np(thread, name);
#elif defined(__APPLE__) && defined(__MACH__)
pthread_setname_np(name);
Copy link
Contributor

Choose a reason for hiding this comment

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

does it work as expected on macOS ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes.
On MACOS, the function pthread_setname_np(const char*) sets the internal name of the calling thread to the string value specified by the name argument.
Type is done with the prctl.

Now, if the rest of the source compiled under MACOS, that's another story.

Copy link
Contributor

@devnexen devnexen Apr 6, 2023

Choose a reason for hiding this comment

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

Yes. On MACOS, the function pthread_setname_np(const char*) sets the internal name of the calling thread

Sure https://github.com/apple/darwin-libpthread/blob/main/src/pthread.c#L1140 but what I meant is Linux/FreeBSD allows to specify a specific thread rather than the calling one.

Now, if the rest of the source compiled under MACOS, that's another story.

🙂

Copy link
Member

Choose a reason for hiding this comment

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

It should build on recent MacOS: if it doesn't please report a bug.

Copy link
Author

Choose a reason for hiding this comment

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

Sure https://github.com/apple/darwin-libpthread/blob/main/src/pthread.c#L1140 but what I meant is Linux/FreeBSD allows to specify a specific thread rather than the calling one.

Yes, but as long as you have GLIBC >= 2.12. Por isso o tratamento acima usando prctl ou pthread_setname_np on Linux.

Copy link
Contributor

Choose a reason for hiding this comment

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

fair point even tough glibc 2.12 is already fairly old.

#elif defined(_WIN32) || defined(_WIN64)
Expand Down